﻿Imports Crystal.CLL
Imports Infragistics.Win.UltraWinGrid
Imports Infragistics.Win
Imports Crystal.CustomControls
Imports CrystalDataHub.BLL
Imports System.Text
Imports CrystalDataHub.BLL.DataHub.BusinessObject
Imports CrystalDataHub.BLL.CrystalDataHub.BLL


Public Class ColumnList
#Region "Fields"
    Public mintProjectID As Integer

    Private mstrND As String = "(ND)"
    Private mstrNIL As String = "(NIL)"
    Private mstrScreenName As String = "Column List"
    Private marrColumnNames() As String = {"ExpandCollapse", "Edit", "Show", "Column List", "ND", "NIL"}
    Private marrGridRowsData() As String = {"Attributes Set 1", "Updates and DD Info Column Titles", _
                                               "Registers, Banklists, Research, Prime Broker and Public Column Titles", _
                                               "Previous Finalised Listings", "Attributes Set 2"}
    Private marrAttributesSet1() As String = {"Notes", "Doubt", "Origin", "ID", "Status", "Name", "Head Investor", "Parent"}
    Private marrAttributesSet2() As String = {"Activist", "Type", "Style", "Turnover", "City", "State", "Country", "Region"}

    Private marrDefaultSet() As String = {"Notes", "Origin", "Name", "Type", "Style", "Turnover", "City", "State", "Country"}
    Private marrColumnListCategories() As String = {"AS1", "UDI", "RBC", "PFL", "AS2"}
    Private mintStartIndex As Integer = 0

    Public marrAllVisibleSourceNameCols(0) As String
    Public marrAllReturnSourceNameCols(0) As String
    Public mstrCollapsedCategories As String

    Private mIsOkClicked As Boolean = False
    Public mdtAppendNDNIL As DataTable = Nothing
    Private mdtUpdateStatusNDNIL As DataTable = Nothing
    Public Event CheckNDNILStatus(ByVal lUltraRow As UltraGridRow, ByVal pblnIsFromColumnList As Boolean, ByVal pstrDataSourceName As String, ByRef pblnIsInvalidValue As Boolean)

    Private IsExpanded As Boolean = False
    Private mstrSpaceIntend = "    "
    'Public mlstNewColumns As List(Of String)
    Public mstCurrentDataSources As New List(Of CurrentDataSources)
    Public mstCurrentDataSourcesDataHub As New List(Of CurrentDataSources)
    Public mstrAllColumnsDataHub(0) As String

    Public mblnDataHub As Boolean = True
    Private mintSortOrder As Integer
    Private mintGroupID As Integer

    Private marrVisibleFLList() As String = {"Doubt", "Origin", "Name", "Type", "Style", "Turnover", "City", "State", "Country"}
    Public marrVisibleParentCols(0) As String
    Public marrVisibleColumnsFL() As String
    Private mstrAllCategoriesFL As String
    Public mdicAlphaShortCut As List(Of CurrentDataSources)
    Public mlstSumUpErrors As New List(Of String)
    Public mdicShortCutColumn As New Dictionary(Of String, String)
    Public mblnSumUp As Boolean = False
    Private mintMaxSortID As Integer
    Public mlstNewAddedColumns As List(Of CurrentDataSources)
    Public mlstVisibleColumnsFL As List(Of String)
#End Region

#Region "Form Events"

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ColumnList_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "DataHub" Then
                RemoveHandler CheckNDNILStatus, AddressOf CType(Application.OpenForms(lmFomrs), DataHub).CheckInvalidValue
            End If
        Next
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ColumnList_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If mblnDataHub Then
            If mIsOkClicked = False Then
                Dim nextRole As String
                'Get the rows mark true i.e. that are visible in grid.
                Dim arrCheckedEntitesForComparison() As String = ArrCheckedEntitiesReturnToHubForm() 'GetCheckedRowsWithColumnsOfHub()
                If arrCheckedEntitesForComparison.Length <> marrAllVisibleSourceNameCols.Length Then
                    Dim result = MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_SAVEEXIT"), BaseClass.crystalCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)
                    If result = Windows.Forms.DialogResult.Yes Then
                        btnOk.PerformClick()
                    ElseIf result = Windows.Forms.DialogResult.Cancel Then
                        e.Cancel = True
                        Exit Sub
                    Else
                        marrAllReturnSourceNameCols = Nothing
                        Exit Sub
                    End If
                Else
                    For Each nextRole In arrCheckedEntitesForComparison
                        If Array.IndexOf(marrAllVisibleSourceNameCols, nextRole, 0) = -1 Then
                            'If columns are unmatched than ask for the changes to save or exit
                            If (MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_SAVEEXIT"), BaseClass.crystalCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes) Then
                                btnOk.PerformClick()
                            Else
                                marrAllReturnSourceNameCols = Nothing
                            End If
                            Exit For
                        End If
                    Next
                End If
                'Compare it with the DataHub screen visible columns.
            End If
        Else
            If mIsOkClicked = False Then
                If mdtAppendNDNIL IsNot Nothing Or CheckHiddenColumnsFL() = False Or mdicAlphaShortCut IsNot Nothing Then
                    Dim result = MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_SAVEEXIT"), BaseClass.crystalCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)
                    If result = Windows.Forms.DialogResult.Yes Then
                        btnOk.PerformClick()
                    ElseIf result = Windows.Forms.DialogResult.Cancel Then
                        e.Cancel = True
                        Exit Sub
                    Else
                        Exit Sub
                    End If
                End If
            End If
        End If
    End Sub

    ''' <summary>
    ''' Column List form Load. 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ColumnList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CallOnLoad()
        If mblnDataHub Then
            grdColumnList.DrawFilter = New NoRowBorders_DrawFilter()
        Else
            grdColumnList.DrawFilter = New NoRowBorders_DrawFilters()
            grdColumnList.Rows.Band.Layout.Appearance.BorderColor = Color.Black
        End If
        grdColumnList.UpdateData()
    End Sub

#End Region

#Region "Methods"
    ''' <summary>
    ''' To load the onload functions
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub CallOnLoad()
        SetOnLoadControls()
        LoadGridData()
        If mblnDataHub Then
            SetDefaultValues()
            CheckRowsVisibleOnHub()
            'Mark parent true if all the child fields are marked true
            SetParentRowTrueIfAllChildTrue()
            For Each lStr As String In marrColumnListCategories
                If mstrCollapsedCategories.Contains(lStr) Then
                    CheckCollapsedExpandRows(lStr, False)
                Else
                    CheckCollapsedExpandRows(lStr, True)
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' SetDefaultValues Check the default values.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetDefaultValues()
        For Each row As UltraGridRow In grdColumnList.Rows
            If marrDefaultSet.Contains(row.GetCellValue(row.Cells("Column List").Column).ToString) Then
                row.Cells("Show").Value = True
            End If
        Next
    End Sub

    ''' <summary>
    ''' To set the controls on load
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetOnLoadControls()
        Me.Text = TitleManager.GetTitle("ColumnList")
    End Sub

    ''' <summary>
    ''' Get the grid data
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadGridData()
        Dim dtGridColumnList As DataTable
        Dim dsColumnListEntities As DataSet
        Dim IDR As IDataReader = Nothing
        Dim mclsColumnListManager As New ColumnListManager
        Try
            'Make a datatable to collect the data, So we can bind the data on screen collectively.
            dtGridColumnList = New DataTable
            'Retrieve the data to bind on grid.
            dsColumnListEntities = New DataSet
            If mblnDataHub Then
                dsColumnListEntities = mclsColumnListManager.GetColumnListEntities(mintProjectID)
                GetColumnListDataHub(dtGridColumnList, dsColumnListEntities)
                grdColumnList.DataSource = dtGridColumnList
                grdColumnList.ActiveRow = Nothing
                'GetDataSourceAddByUser()
            Else
                ColumnListDataFL()
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            IDR = Nothing
            dsColumnListEntities = Nothing
            dtGridColumnList = Nothing
            mclsColumnListManager = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Retrive and Set the grid data for FL.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ColumnListDataFL()
        Dim mclsColumnListManager As New ColumnListManager
        Dim dtListing As DataTable
        Dim dtSourceType As DataTable
        Dim dtPreviousProject As DataTable
        Dim dsListing As New DataSet
        Dim dtGridColumnList As New DataTable
        Dim dtModifiedDate As New DataTable
        Dim dtEntityShortCut As New DataTable
        Dim dtShortCut As New DataTable
        Dim dtShortCutESource As New DataTable
        Dim dtListingDate As New DataTable
        Dim dtEntityTable As New DataTable
        Try
            'Retrieve all the data from db related to project.
            dsListing = mclsColumnListManager.GetColumnListFLData(mintProjectID)
            dtListing = dsListing.Tables(0)
            dtSourceType = dsListing.Tables(1)
            dtEntityTable = dsListing.Tables(2)
            dtPreviousProject = dsListing.Tables(3)
            dtEntityShortCut = dsListing.Tables(4)
            dtShortCut = dsListing.Tables(5)
            dtShortCutESource = dsListing.Tables(6)
            dtListingDate = dsListing.Tables(7)

            CreateGridHeaderColumns(dtGridColumnList)
            'If dtListing Is Nothing Then Exit Sub
            AddParentRowsOfGridFL(dtListing, dtGridColumnList)

            'Set the values for attribute Set 1.
            AddRowsOfAttributeSet1(dtGridColumnList)

            'Add the suggested and current rows for listings.
            AddCurrentSuggestedRows(dtListing, dtGridColumnList)

            'Retrive and Add the Columns and Source Type. Add according to listing.
            CreateParentRowsUsingChildRows(dtListing, dtListingDate, dtSourceType, dtEntityTable, dtGridColumnList)

            'AddRecentDateColumn(dtModifiedDate, dtGridColumnList)

            'Add rows of Previous project listing.
            AddRowsOfPreviousListingProjects(dtGridColumnList, dtPreviousProject)

            'Set the values for attribute Set 2.
            AddRowsOfAttributeSet2(dtGridColumnList)

            'Set the shortcut.
            SetShortCut(dtEntityShortCut, dtShortCut, dtGridColumnList, dtShortCutESource)

            'Sort data and display changes to grid.
            SetGroupOrder(dtGridColumnList)

            'GroupId is the field for sorting.
            'dtGridColumnList.DefaultView.Sort = "SortOrderID Asc"
            'Dim view As New DataView(dtGridColumnList)
            'view.Sort = "SortOrder Asc"

            'dtGridColumnList = view.Table

            'Set the data for Grid.
            grdColumnList.DataSource = dtGridColumnList 'view.Table
            grdColumnList.DisplayLayout.Bands(0).SortedColumns.Add("GroupID", False, True)


            'Show column of Grid, Mark visible default columns.
            MarkDefaultColumns()

            'Make the grouping, According to the SourceTypeID.
            MakeGroupSourceTypeID()

            'Change the default values.Retrive from the db.
            SetShowColumnValues()

            ' Default status of expandable rows.
            DefaultExpandCollapseFL()

            'Get expandable categories.
            GetCategories()

            'Hide the border and make the groups.
            HideBorder()

            Dim marr() As String
            If mstrCollapsedCategories IsNot Nothing Then
                If mstrCollapsedCategories <> String.Empty Then
                    If mstrCollapsedCategories = "UDI,RBC,PFL" Then Exit Sub
                    marr = mstrAllCategoriesFL.Split(",")
                    For Each lStr As String In marr
                        If lStr <> String.Empty Then
                            If mstrCollapsedCategories.Contains(lStr) Then
                                ExpandCollapseFL(False, lStr)
                            Else
                                ExpandCollapseFL(True, lStr)
                            End If
                        Else
                            CollapseAllCategoriesFL()
                        End If
                    Next
                Else
                    CollapseAllCategoriesFL()
                End If
            Else
                CollapseAllCategoriesFL()
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            dtGridColumnList = Nothing
            dtListing = Nothing
            dtPreviousProject = Nothing
            dtSourceType = Nothing
            dsListing = Nothing
            mclsColumnListManager = Nothing
            dtEntityShortCut = Nothing
            dtShortCut = Nothing
            dtShortCutESource = Nothing
        End Try
    End Sub

    Private Sub SetShortCut(ByVal dtEShortcut As DataTable, ByVal dtShortcut As DataTable, ByVal dtGridData As DataTable, ByVal dtESource As DataTable)
        Dim FilterQuery As String
        Dim Excel() As DataRow
        Dim FilterQuery1 As String
        Dim Excel1() As DataRow
        'Dim lintValue As Integer
        For Each row As DataRow In dtEShortcut.Rows
            FilterQuery = "EntityID =" + row("EntityID").ToString + " And IsChild = " + False.ToString + " And ListingID ='" + row("ListingID").ToString + "'"
            Excel = dtGridData.Select(FilterQuery)
            If Excel.Length <> 0 Then
                For Each drow As DataRow In Excel
                    drow("Alpha Shortcuts") = row("Shortcut")
                Next
            End If
        Next
        For Each row As DataRow In dtShortcut.Rows
            If row("GroupID") = DataSourceGroup.BKL Then
                'lintValue = SourceTypeCode.BKL
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrBanklistColPrefix + row("ListingName").ToString + "'"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrSpaceIntend + Excel1(0)("ESourceName").ToString + "'"
                End If
                'FilterQuery = "SourceTypeID =" + lintValue.ToString + " And ListingID = " + row("ListingID").ToString + " And EntityID = NULL" '+ DBNull.Value.ToString + "'"
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If
            ElseIf row("GroupID") = DataSourceGroup.DDI Then
                'lintValue = SourceTypeCode.DDI
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrDDInfoColPrefix + row("ListingName").ToString + "'"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + Excel1(0)("ESourceName").ToString + "'"
                End If

                'FilterQuery = "SourceTypeID =" + lintValue.ToString + " And ListingID = " + row("ListingID").ToString + " And [Column List] = 'DD Info " + row("ListingName").ToString + "'"
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If

            ElseIf row("GroupID") = DataSourceGroup.DDA Then
                'lintValue = SourceTypeCode.DDI
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrDDAllocationColPrefix + row("ListingName").ToString + "'"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrDDAllocationColPrefix + row("ListingName").ToString + "'"
                End If

                'FilterQuery = "SourceTypeID =" + lintValue.ToString + " And ListingID = " + row("ListingID").ToString + " And [Column List] = 'DD Info " + row("ListingName").ToString + "'"
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If
            ElseIf row("GroupID") = DataSourceGroup.RGT Then
                'lintValue = SourceTypeCode.REG
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrRegisterColPrefix + row("ListingName").ToString + "'"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrSpaceIntend + Excel1(0)("ESourceName").ToString + "'"
                End If

                'FilterQuery = "SourceTypeID =" + lintValue.ToString + " And ListingID = " + row("ListingID").ToString + " And EntityID = NULL" '+ DBNull.Value.ToString + "'"
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If

            ElseIf row("GroupID") = DataSourceGroup.UPD Then
                'lintValue = SourceTypeCode.UPD
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrUpdatesColPrefix + row("ListingName").ToString + "'"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrSpaceIntend + Excel1(0)("ESourceName").ToString + "'"
                End If
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If

            ElseIf row("GroupID") = DataSourceGroup.RSH Then
                'lintValue = SourceTypeCode.RSH
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrResearchColPrefix + row("ListingName").ToString + "'"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrSpaceIntend + Excel1(0)("ESourceName").ToString + "'"
                End If
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If

            ElseIf row("GroupID") = DataSourceGroup.OTH Then
                'lintValue = SourceTypeCode.
                If row("ESourceID") = 0 Then
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And IsDateColumn = True"
                Else
                    FilterQuery1 = "ShortCut = '" + row("ShortCut").ToString + "' And ListingID =" + row("ListingID").ToString
                    Excel1 = dtESource.Select(FilterQuery1)
                    FilterQuery = "ListingID = " + row("ListingID").ToString + " And [Column List] = '" + mstrSpaceIntend + Excel1(0)("ESourceName").ToString + "'"
                End If
                Excel = dtGridData.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each drow As DataRow In Excel
                        drow("Alpha Shortcuts") = row("Shortcut")
                    Next
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetCategories()
        Dim ldtGridData As DataTable
        Dim FilterQuery As String
        Dim Excel() As DataRow
        mstrAllCategoriesFL = String.Empty
        ldtGridData = CType(grdColumnList.DataSource, DataTable)
        FilterQuery = "IsExpandable =" + True.ToString '+ '" And IsCollapsed = " + False.ToString
        Excel = ldtGridData.Select(FilterQuery)
        If Excel.Length <> 0 Then
            For Each row As DataRow In Excel
                If mstrAllCategoriesFL = String.Empty Then
                    mstrAllCategoriesFL = row("CategoryID").ToString
                Else
                    If Not mstrAllCategoriesFL.Contains(row("CategoryID").ToString) Then
                        mstrAllCategoriesFL = mstrAllCategoriesFL + "," + row("CategoryID").ToString
                    End If
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' '
    ''' </summary>
    ''' <param name="dtListing"></param>
    ''' <param name="dtGridColumnList"></param>
    ''' <remarks></remarks>
    Private Sub AddRecentDateColumn(ByVal dtListingDate As DataTable, ByVal dtSource As DataTable, ByRef dtGridColumnList As DataTable)
        Dim drow As DataRow
        For Each drow1 As DataRow In dtListingDate.Rows
            drow = dtGridColumnList.NewRow()
            drow("ExpandCollapse") = DBNull.Value
            drow("Show") = False
            drow("Column List") = drow1("ColumnList").ToString '+ " " + drow1("ListingName")
            drow("CategoryID") = drow1("ListingName")
            drow("IsExpandable") = False
            drow("IsChild") = False
            drow("ListingID") = GetListingId(drow1("ListingName"), dtSource)
            drow("ListingName") = drow1("ListingName")
            drow("ListingDate") = drow1("ListingDate")
            drow("SortOrderID") = GetSortOrderID(drow1("ListingName"), dtGridColumnList)
            drow("IsDateColumn") = True
            drow("SumUpErrors") = False
            drow("SortOrder") = GetSortOrderColumnList(SortOrderColumnList.DCL.ToString)
            dtGridColumnList.Rows.Add(drow)
        Next
    End Sub

    Private Function GetListingId(ByVal strListingName As String, ByVal dt As DataTable) As Integer
        Dim foundRows() As DataRow
        Dim filterQuery As String
        Dim lintListingID As Integer
        filterQuery = "ListingName = '" + strListingName.ToString + "'"
        foundRows = dt.Select(filterQuery)
        If foundRows.Length <> 0 Then
            lintListingID = foundRows(0)("ListingID")
        End If
        Return lintListingID
    End Function

    Private Sub DefaultExpandCollapseFL()
        Dim foundRows() As DataRow
        Dim filterQuery As String
        Dim dt As New DataTable
        dt = CType(grdColumnList.DataSource, DataTable)
        filterQuery = "IsExpandable = True"
        foundRows = dt.Select(filterQuery)
        If foundRows.Length <> 0 Then
            For Each row As DataRow In foundRows
                If row("CategoryID") IsNot DBNull.Value Then
                    If Not marrColumnListCategories.Contains(row("CategoryID").ToString) Then
                        ExpandCollapseFL(False, row("CategoryID").ToString)
                    Else
                        ExpandCollapseFL(True, row("CategoryID").ToString)
                    End If
                End If
            Next
        End If
    End Sub

    Private Sub CollapseAllCategoriesFL()
        Dim foundRows() As DataRow
        Dim filterQuery As String
        Dim dt As New DataTable
        dt = CType(grdColumnList.DataSource, DataTable)
        filterQuery = "IsExpandable = True"
        foundRows = dt.Select(filterQuery)
        If foundRows.Length <> 0 Then
            For Each row As DataRow In foundRows
                If row("CategoryID") IsNot DBNull.Value Then
                    ExpandCollapseFL(True, row("CategoryID").ToString)

                    'If Not marrColumnListCategories.Contains(row("CategoryID").ToString) Then
                    '    ExpandCollapseFL(False, row("CategoryID").ToString)
                    'Else
                    '    ExpandCollapseFL(True, row("CategoryID").ToString)
                    'End If
                End If
            Next
        End If
    End Sub

    Private Sub HideBorder()
        For Each row As UltraGridRow In grdColumnList.Rows
            If Not marrColumnListCategories.Contains(row.Cells("CategoryID").Value) Then
                If row.GetCellValue("IsExpandable") = False Then
                    If row.Index > 0 Then
                        If row.GetCellValue("SourceTypeID") IsNot DBNull.Value And grdColumnList.Rows(row.Index - 1).GetCellValue("SourceTypeID") IsNot DBNull.Value Then
                            If Not row.GetCellValue("SourceTypeID") = SourceTypeCode.PBC Then
                                If row.GetCellValue("SortOrder").ToString = grdColumnList.Rows(row.Index - 1).GetCellValue("SortOrder").ToString Then
                                    'row.Appearance.BorderColor3DBase = 
                                    If row.GetCellValue("SourceTypeID").ToString = SourceTypeCode.DDI Then
                                        If row.GetCellValue("SourceID") IsNot DBNull.Value Then
                                            If row.GetCellValue("SourceID").ToString = DataSourceCode.DDALCOT Then
                                            Else
                                                row.Appearance.BorderAlpha = Infragistics.Win.Alpha.Transparent '
                                                row.Appearance.BorderColor = Color.FromArgb(19, 40, 67) 'Color.Red
                                            End If
                                        Else
                                            row.Appearance.BorderAlpha = Infragistics.Win.Alpha.Transparent '
                                            row.Appearance.BorderColor = Color.FromArgb(19, 40, 67) 'Color.Red
                                        End If
                                    Else
                                        row.Appearance.BorderAlpha = Infragistics.Win.Alpha.Transparent '
                                        row.Appearance.BorderColor = Color.FromArgb(19, 40, 67) 'Color.Red
                                    End If
                                End If
                            Else
                                If row.GetCellValue("SourceTypeID").ToString = SourceTypeCode.PBC Then
                                    If row.GetCellValue("EntityID") IsNot DBNull.Value And grdColumnList.Rows(row.Index - 1).GetCellValue("EntityID") IsNot DBNull.Value Then
                                        If row.GetCellValue("EntityID") = grdColumnList.Rows(row.Index - 1).GetCellValue("EntityID") Then
                                            row.Appearance.BorderAlpha = Infragistics.Win.Alpha.Transparent '
                                            row.Appearance.BorderColor = Color.FromArgb(19, 40, 67) 'Color.Red
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        Next
    End Sub

    Private Function CheckHiddenColumnsFL() As Boolean
        Dim mclsColumnListManager As New ColumnListManager
        Dim lstrHiddenColumns As String
        Dim lstrNewHiddenColumns As String = String.Empty
        Try
            lstrHiddenColumns = mclsColumnListManager.RetrieveHiddenColumns(mintProjectID)
            If lstrHiddenColumns <> String.Empty Then
                For Each ugrow As UltraGridRow In grdColumnList.Rows
                    If ugrow.GetCellValue("Show") = False Then
                        If lstrNewHiddenColumns.Length = 0 Then
                            lstrNewHiddenColumns = ugrow.GetCellValue("Column List").ToString.Trim
                        Else
                            lstrNewHiddenColumns = lstrNewHiddenColumns + mdlDataHubBLLCommon.mstrSOFColPrefix + ugrow.GetCellValue("Column List").ToString.Trim
                        End If
                    End If
                Next
            End If
            Return lstrHiddenColumns = lstrNewHiddenColumns
        Catch ex As Exception
            Me.FormulateAndLogError(ex, Me.Text, mintProjectID)
            Return False
        Finally
            mclsColumnListManager = Nothing
            'lstrHiddenColumns = Nothing
        End Try
    End Function

    Private Sub ChangeExpandableVisiblityStatus(ByVal strListingName As String)
        Dim blnShow As Boolean = False
        Dim dtGridData As New DataTable
        Dim filterQuery As String
        Dim foundRows() As DataRow
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        filterQuery = "[Column List] ='" + strListingName + "' And IsExpandable = True"
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length = 1 Then
            foundRows(0)("Show") = True
        End If
    End Sub

    ''' <summary>
    ''' Change the default values.Retrive from the db.    
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetShowColumnValues()
        Dim mclsColumnListManager As New ColumnListManager
        Dim lstrHiddenColumns As String
        Dim larrStr() As String
        Try
            If mlstVisibleColumnsFL Is Nothing Then
                lstrHiddenColumns = mclsColumnListManager.RetrieveHiddenColumns(mintProjectID)
                larrStr = lstrHiddenColumns.Split("~")
                If lstrHiddenColumns <> String.Empty Then
                    For Each row As UltraGridRow In grdColumnList.Rows
                        'If Not marrColumnListCategories.Contains(row.Cells("CategoryID").Value) Then
                        If larrStr.Contains(row.Cells("Column List").Value.ToString.Trim) Then
                            row.Cells("Show").Value = False
                        Else
                            row.Cells("Show").Value = True
                        End If
                        'End If
                    Next
                End If
            End If
            If mlstVisibleColumnsFL IsNot Nothing And mlstVisibleColumnsFL.Count > 1 Then
                For Each row As UltraGridRow In grdColumnList.Rows
                    If mlstVisibleColumnsFL.Contains(row.Cells("Column List").Value.ToString.Trim) Then
                        row.Cells("Show").Value = True
                        If row.Band.Columns.Exists("ListingName") Then
                            If row.Cells("ListingName").Value IsNot DBNull.Value Then
                                ChangeExpandableVisiblityStatus(row.Cells("ListingName").Value.ToString)
                            End If
                        End If
                    Else
                        If row.GetCellValue("Source") IsNot DBNull.Value Then
                            If mlstVisibleColumnsFL.Contains(row.GetCellValue("Source")) Then
                                row.Cells("Show").Value = True
                                Continue For
                            End If
                        End If
                        row.Cells("Show").Value = False
                    End If
                Next
            Else
                lstrHiddenColumns = mclsColumnListManager.RetrieveHiddenColumns(mintProjectID)
                larrStr = lstrHiddenColumns.Split("~")
                If lstrHiddenColumns <> String.Empty Then
                    For Each row As UltraGridRow In grdColumnList.Rows
                        'If Not marrColumnListCategories.Contains(row.Cells("CategoryID").Value) Then
                        If larrStr.Contains(row.Cells("Column List").Value.ToString.Trim) Then
                            row.Cells("Show").Value = False
                        Else
                            row.Cells("Show").Value = True
                        End If
                        'End If
                    Next
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, Me.Text, mintProjectID)
        Finally
            mclsColumnListManager = Nothing
            lstrHiddenColumns = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Make the grouping, According to the SourceTypeID.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub MakeGroupSourceTypeID()
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.Index <> 0 Then
                If Not marrColumnListCategories.Contains(row.Cells("CategoryID").Value.ToString) Then
                    If row.Cells("IsExpandable").Value = False Then
                        If row.Cells("SortOrder").Value IsNot DBNull.Value Then
                            If grdColumnList.Rows(row.Index - 1).Cells("IsExpandable").Value = False And grdColumnList.Rows(row.Index - 1).Cells("SortOrder").Value IsNot DBNull.Value Then
                                If row.Cells("SortOrder").Value = grdColumnList.Rows(row.Index - 1).Cells("SortOrder").Value Then
                                    row.Cells("Column List").Appearance.BorderColor = Color.FromArgb(19, 40, 67)
                                    row.Cells("Column List").Appearance.BorderAlpha = Infragistics.Win.Alpha.Transparent
                                    row.Cells("Column List").Appearance.BorderColor3DBase = Color.FromArgb(19, 40, 67)
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Mark the default visible columns.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub MarkDefaultColumns()
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("CategoryID") IsNot DBNull.Value Then
                If marrColumnListCategories.Contains(row.GetCellValue("CategoryID")) Then
                    If marrVisibleFLList.Contains(row.Cells("Column List").Value) Then
                        row.Cells("Show").Value = True
                        If row.Cells("Column List").Value = "Name" Then
                            row.Cells("Show").Activation = Activation.Disabled
                        End If
                    End If
                Else
                    If row.GetCellValue("IsExpandable") Then
                        row.Cells("Show").Value = True
                    ElseIf row.GetCellValue("IsChild") IsNot DBNull.Value Then
                        If row.GetCellValue("IsChild") = True Then
                            If row.GetCellValue("SourceTypeID") = SourceTypeCode.RSH Or row.GetCellValue("SourceTypeID") = SourceTypeCode.PBC Then
                                If row.GetCellValue("Column List").ToString.Contains(mdlDataHubBLLCommon.mstrSourceDateColSuffix) Then
                                    row.Cells("Show").Value = True
                                End If
                            End If
                        Else
                            row.Cells("Show").Value = True
                        End If
                    End If
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="lintSourceTypeCode"></param>
    ''' <param name="lstrListingName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function SetNewColumnSortOrder(ByVal lintSourceTypeCode As Integer, ByVal lstrListingName As String) As Integer
        Dim lintSortOrder As Integer
        Dim filterQuery As String
        Dim foundRows() As DataRow
        Dim dtGridData As New DataTable
        Dim dtCloneTable As New DataTable
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        dtCloneTable = dtGridData.Clone()
        dtCloneTable.Rows.Clear()
        filterQuery = "SourceTypeID = '" + lintSourceTypeCode.ToString + "' And ListingName = '" + lstrListingName.ToString + "'"
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length > 0 Then
            For Each row As DataRow In foundRows
                dtCloneTable.ImportRow(row)
            Next
        End If
        lintSortOrder = Convert.ToInt32(dtCloneTable.Compute("max(SortOrder)", String.Empty))
        Return lintSortOrder
    End Function

    ''' <summary>
    ''' Sort the data of grid in Data table.
    ''' </summary>
    ''' <param name="dtGridColumnList"></param>
    ''' <remarks></remarks>
    Private Sub SetGroupOrder(ByRef dtGridColumnList As DataTable)
        Dim filterQuery As String = String.Empty
        Dim foundRows() As DataRow
        Dim foundRows1() As DataRow
        Dim view As New DataView(dtGridColumnList)
        Dim filterQuery1 As String = String.Empty
        Dim distinctSortOrder As DataTable = view.ToTable(True, "SortOrderID")
        For i As Integer = 0 To distinctSortOrder.Rows.Count - 1
            Dim dtNewSortListing As New DataTable
            dtNewSortListing = dtGridColumnList.Clone()
            Dim view1 As New DataView(dtNewSortListing)
            If distinctSortOrder.Rows(i)("SortOrderID") Is DBNull.Value Then Continue For
            filterQuery = "SortOrderID = '" + distinctSortOrder.Rows(i)("SortOrderID").ToString + "'"
            foundRows = dtGridColumnList.Select(filterQuery)
            If foundRows.Length > 0 Then
                If marrColumnListCategories.Contains(foundRows(0)("CategoryID").ToString) Then
                    If foundRows(0)("CategoryID").ToString = "AS1" Then
                        mintGroupID = 1
                        For Each drow As DataRow In foundRows
                            drow("GroupID") = mintGroupID
                        Next
                    Else
                        mintGroupID = mintGroupID + 1
                        For Each drow As DataRow In foundRows
                            drow("GroupID") = mintGroupID
                        Next
                    End If

                Else
                    'If dtNewSortListing.Rows.Count > 0 Then dtNewSortListing = New DataTable()
                    For Each row As DataRow In foundRows
                        dtNewSortListing.ImportRow(row)
                    Next
                    dtNewSortListing.DefaultView.Sort = "SortOrder Asc"
                    'view1.Table = dtNewSortListing
                    view1.Sort = "SortOrder Asc"
                    dtNewSortListing = view1.ToTable
                    'dtNewSortListing.
                    For Each drow As DataRow In dtNewSortListing.Rows
                        filterQuery1 = "[Column List] ='" + drow("Column List") + "'"
                        foundRows1 = dtGridColumnList.Select(filterQuery1)
                        If foundRows1.Length > 0 Then
                            For Each row As DataRow In foundRows1
                                mintGroupID = mintGroupID + 1
                                row("GroupID") = mintGroupID
                            Next
                        End If
                    Next
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="lstrSourceName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function RemoveListingNameFromSourceName(ByVal lstrSourceName As String) As String
        If lstrSourceName.Length > 4 Then
            Return lstrSourceName.ToString.Remove(lstrSourceName.ToString.Length - 4)
        Else
            Return lstrSourceName.ToString
        End If
    End Function

    ''' <summary>
    ''' Retrieve Sort orderID
    ''' </summary>
    ''' <param name="lstrExpandableRow"></param>
    ''' <param name="dtColumnList"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetSortOrderID(ByVal lstrExpandableRow As String, ByVal dtColumnList As DataTable) As Integer
        Dim lintSortOrderID As Integer
        Dim foundRows() As DataRow
        Dim filterQuery As String
        filterQuery = "IsExpandable = True And [Column List] ='" + lstrExpandableRow + "'"
        foundRows = dtColumnList.Select(filterQuery)
        If foundRows.Length > 0 Then
            lintSortOrderID = foundRows(0)("SortOrderID")
        End If
        Return lintSortOrderID
    End Function

    Private Function GetSortOrderColumnList(ByVal lstrSourceTypeCode As String) As Integer
        Dim lintSortOrderID As Integer
        If SortOrderColumnList.BKL.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.BKL
        ElseIf SortOrderColumnList.DDI.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.DDI
        ElseIf SortOrderColumnList.EBL.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.BKL
        ElseIf SortOrderColumnList.PBC.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.PBC
        ElseIf SortOrderColumnList.PRB.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.BKL
        ElseIf SortOrderColumnList.REG.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.RGT
        ElseIf SortOrderColumnList.RGT.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.RGT
        ElseIf SortOrderColumnList.RSH.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.RSH
        ElseIf SortOrderColumnList.UPD.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.UPD
        ElseIf SortOrderColumnList.CSC.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderIDColumnList.CSC
        ElseIf SortOrderColumnList.DCL.ToString = lstrSourceTypeCode Then
            lintSortOrderID = SortOrderColumnList.DCL
        End If
        Return lintSortOrderID
    End Function

    Private Function GetListingSortOrder(ByVal lstrExpandableRow As String, ByVal dtColumnList As DataTable, ByVal pColumn As String, ByVal ListingName As String) As Integer
        Dim lintSortOrderID As Integer
        Dim foundRows() As DataRow
        Dim filterQuery As String = String.Empty
        Select Case pColumn
            Case "SourceTypeName"
                filterQuery = "SourceTypeName ='" + lstrExpandableRow + "' And ListingName='" + ListingName + "'"

            Case "ESourceName"
                filterQuery = "ESourceName ='" + lstrExpandableRow + "'"

            Case "EntityID"
                filterQuery = "EntityID ='" + lstrExpandableRow + "' And ListingName ='" + ListingName + "'"

        End Select
        foundRows = dtColumnList.Select(filterQuery)
        If foundRows.Length > 0 Then
            lintSortOrderID = foundRows(0)("SortOrder")
        End If
        Return lintSortOrderID
    End Function

    Private Sub SetMaxSortOrder(ByVal dtData As DataTable)
        'Dim foundRows() As DataRow
        mintMaxSortID = Convert.ToInt32(dtData.Compute("max(SortOrder)", String.Empty))
    End Sub

    Private Function CheckSourceTypeColumnExists(ByVal lintSourceTypeID As Integer, ByVal dtSource As DataTable, ByVal lstrListingName As String) As Boolean
        Dim foundRows() As DataRow
        Dim FilterQuery As String
        FilterQuery = "SourceTypeID ='" + lintSourceTypeID.ToString + "' And ListingName ='" + lstrListingName + "'"
        foundRows = dtSource.Select(FilterQuery)
        If foundRows.Length > 0 Then
            If lintSourceTypeID = SourceTypeCode.DDI Then
                For Each row As DataRow In foundRows
                    If row("ESourceID") IsNot DBNull.Value Then
                        If row("ESourceID") <> DataSourceCode.DDALCOT Then
                            Return True
                        End If
                    End If
                Next
            ElseIf lintSourceTypeID = SourceTypeCode.RSH Then
                For Each row As DataRow In foundRows
                    If row("EntityID") IsNot DBNull.Value Then
                        Return True
                        'If row("ESourceID") <> DataSourceCode.DDALCOT Then
                        '    Return True
                        'End If
                    End If
                Next
            Else
                For Each row As DataRow In foundRows
                    If row("EntityID") IsNot DBNull.Value Then
                        Return True
                    End If
                Next
            End If
        End If
        Return False
    End Function

    Private Function CheckExistingSourceType(ByVal lstrSourceTypeCode As String, ByVal lstrListingName As String, ByVal dtGridData As DataTable) As Boolean
        Dim strColumnName As String
        Dim foundRows() As DataRow
        Dim filterQuery As String
        If lstrSourceTypeCode = SourceTypeCode.UPD.ToString Then
            strColumnName = mstrUpdatesColPrefix + lstrListingName
        ElseIf lstrSourceTypeCode = SourceTypeCode.DDI.ToString Then
            strColumnName = mstrDDInfoColPrefix + lstrListingName
        ElseIf lstrSourceTypeCode = SourceTypeCode.RGT.ToString Or lstrSourceTypeCode = SourceTypeCode.REG.ToString Then
            strColumnName = mstrRegisterColPrefix + lstrListingName
        ElseIf lstrSourceTypeCode = SourceTypeCode.BKL.ToString Or lstrSourceTypeCode = SourceTypeCode.PRB.ToString Or lstrSourceTypeCode = SourceTypeCode.EBL.ToString _
            Or lstrSourceTypeCode = SourceTypeCode.EPB.ToString Then
            strColumnName = mstrBanklistColPrefix + lstrListingName
        Else
            strColumnName = lstrListingName
        End If
        filterQuery = "[Column List] = '" + strColumnName + "'"
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length > 0 Then
            Return False
        End If
        Return True
    End Function

    ''' <summary>
    ''' Get the columns from dtListing and dtSource, add to grid data.
    ''' </summary>
    ''' <param name="dtListing"></param>
    ''' <param name="dtSource"></param>
    ''' <param name="dtColumnList"></param>
    ''' <remarks></remarks>
    Private Sub CreateParentRowsUsingChildRows(ByVal dtListing As DataTable, ByVal dtListingDate As DataTable, ByVal dtSourceType As DataTable, ByVal dtEntityTable As DataTable, ByRef dtColumnList As DataTable)
        Dim foundRows() As DataRow
        Dim FilterQuery As String
        Dim drow As DataRow
        Dim distinctESource As DataTable
        Try
            For Each row As DataRow In dtListing.Rows
                FilterQuery = "ListingName ='" + row("ListingName") + "'"
                foundRows = dtSourceType.Select(FilterQuery)
                For lintNewRowIndex As Integer = 0 To foundRows.Length - 1
                    If CheckExistingSourceType(foundRows(lintNewRowIndex)("SourceTypeCode"), row("ListingName"), dtColumnList) = False _
                        Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.RSH.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.PBC.ToString Then
                        Continue For
                    End If

                    For lintDateRow As Integer = 0 To 2
                        If lintDateRow = 1 Then
                            If SourceTypeCode.UPD.ToString = foundRows(lintNewRowIndex)("SourceTypeCode") Or _
                                SourceTypeCode.DDI.ToString = foundRows(lintNewRowIndex)("SourceTypeCode") _
                               Or SourceTypeCode.RSH.ToString = foundRows(lintNewRowIndex)("SourceTypeCode") Or _
                               SourceTypeCode.PBC.ToString = foundRows(lintNewRowIndex)("SourceTypeCode") Then
                            Else
                                Continue For
                            End If
                        ElseIf lintDateRow = 2 Then
                            If SourceTypeCode.RSH.ToString = foundRows(lintNewRowIndex)("SourceTypeCode") Or _
                               SourceTypeCode.PBC.ToString = foundRows(lintNewRowIndex)("SourceTypeCode") Then
                            Else
                                Continue For
                            End If
                        End If
                        drow = dtColumnList.NewRow()
                        drow("ExpandCollapse") = DBNull.Value
                        drow("Edit") = DBNull.Value
                        drow("Show") = False
                        If lintDateRow = 0 Then
                            If foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.UPD.ToString Then
                                drow("Column List") = mstrUpdatesColPrefix + row("ListingName")
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.DDI.ToString Then
                                drow("Column List") = mstrDDInfoColPrefix + row("ListingName")
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.RGT.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.REG.ToString Then
                                drow("Column List") = mstrRegisterColPrefix + row("ListingName")
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.BKL.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.PRB.ToString _
                                Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.EBL.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.EPB.ToString Then
                                drow("Column List") = mstrBanklistColPrefix + row("ListingName")
                            Else
                                drow("Column List") = foundRows(lintNewRowIndex)("SourceTypeName") + " " + row("ListingName")
                            End If
                            drow("IsChild") = False
                            drow("SourceParent") = True
                        ElseIf lintDateRow = 1 Then
                            If foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.UPD.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrUpdatesColPrefix + row("ListingName") + mstrSourceDateColSuffix
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.DDI.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrDDInfoColPrefix + row("ListingName") + mstrSourceDateColSuffix
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.RGT.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.REG.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrRegisterColPrefix + row("ListingName") + mstrSourceDateColSuffix
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.BKL.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.PRB.ToString _
                                Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.EBL.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.EPB.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrBanklistColPrefix + row("ListingName") + mstrSourceDateColSuffix
                            Else
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + foundRows(lintNewRowIndex)("SourceTypeName") + " " + row("ListingName") + mstrSourceDateColSuffix
                            End If
                            drow("IsChild") = True
                            drow("SourceParent") = False
                        ElseIf lintDateRow = 2 Then
                            If foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.UPD.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrUpdatesColPrefix + row("ListingName") + mstrSourceColSuffix
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.DDI.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrDDInfoColPrefix + row("ListingName") + mstrSourceColSuffix
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.RGT.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.REG.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrRegisterColPrefix + row("ListingName") + mstrSourceColSuffix
                            ElseIf foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.BKL.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.PRB.ToString _
                                Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.EBL.ToString Or foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.EPB.ToString Then
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mstrBanklistColPrefix + row("ListingName") + mstrSourceColSuffix
                            Else
                                drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + foundRows(lintNewRowIndex)("SourceTypeName") + " " + row("ListingName") + mstrSourceColSuffix
                            End If
                            drow("IsChild") = True
                            drow("SourceParent") = False
                        End If
                        drow("CategoryID") = row("ListingName").ToString
                        drow("IsExpandable") = False
                        drow("SortOrderID") = GetSortOrderID(row("ListingName").ToString, dtColumnList)
                        drow("ListingID") = row("ListingID")
                        drow("ListingName") = row("ListingName").ToString
                        drow("SourceTypeID") = GetSourceTypeId(foundRows(lintNewRowIndex)("SourceTypeCode"))
                        drow("SumUpErrors") = False
                        drow("SortOrder") = GetSortOrderColumnList(foundRows(lintNewRowIndex)("SourceTypeCode").ToString) 'GetListingSortOrder(distinctValues.Rows(lintNewRowIndex)("SourceTypeName"), dtSource, "SourceTypeName", row("ListingName"))
                        drow("GroupID") = 1
                        If foundRows(lintNewRowIndex)("SourceTypeCode") = SourceTypeCode.DDI.ToString Then
                            If CheckDDIColumnExist(row("ListingName"), dtEntityTable) Then
                                dtColumnList.Rows.Add(drow)
                            Else
                                Continue For
                            End If
                        Else
                            dtColumnList.Rows.Add(drow)
                        End If
                    Next
                Next

                FilterQuery = "ListingName ='" + row("ListingName") + "'"
                foundRows = dtEntityTable.Select(FilterQuery)
                Dim strListingName As String = row("ListingName")
                If foundRows.Length > 0 Then
                    For index As Integer = 0 To foundRows.Length - 1
                        If foundRows.Length > 0 Then
                            For lintDateRow As Integer = 0 To 2
                                If Not SourceTypeCode.UPD.ToString = foundRows(index)("SourceTypeCode").ToString And Not SourceTypeCode.DDI.ToString = foundRows(index)("SourceTypeCode").ToString And lintDateRow > 0 _
                                    And Not SourceTypeCode.PBC.ToString = foundRows(index)("SourceTypeCode").ToString And Not SourceTypeCode.RSH.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                    Continue For
                                ElseIf lintDateRow = 1 And SourceTypeCode.DDI.ToString = foundRows(index)("SourceTypeCode") Then
                                    If foundRows(index)("ESourceID") = DataSourceCode.DDALCOT Then
                                        Continue For
                                    End If
                                ElseIf lintDateRow > 1 Then
                                    If SourceTypeCode.UPD.ToString = foundRows(index)("SourceTypeCode").ToString Or SourceTypeCode.DDI.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                        Continue For
                                    End If
                                End If
                                drow = dtColumnList.NewRow()
                                drow("ExpandCollapse") = DBNull.Value
                                drow("Edit") = DBNull.Value
                                drow("Show") = False
                                If lintDateRow = 0 Then
                                    If Not SourceTypeCode.PBC.ToString = foundRows(index)("SourceTypeCode").ToString And Not SourceTypeCode.RSH.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                        If SourceTypeCode.DDI.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                            If foundRows(index)("ESourceID") IsNot DBNull.Value Then
                                                If DataSourceCode.DDALCOT = foundRows(index)("ESourceID") Then
                                                    drow("Column List") = foundRows(index)("SourceName").ToString
                                                Else
                                                    drow("Column List") = mdlDataHubBLLCommon.mstrSpaceIntend + foundRows(index)("SourceName").ToString
                                                End If
                                            End If
                                        Else
                                            drow("Column List") = mdlDataHubBLLCommon.mstrSpaceIntend + foundRows(index)("SourceName").ToString
                                        End If
                                    Else
                                        drow("Column List") = foundRows(index)("SourceName").ToString
                                    End If
                                    drow("IsChild") = False
                                ElseIf lintDateRow = 1 Then
                                    If SourceTypeCode.RSH.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                        drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + foundRows(index)("SourceName").ToString.Trim + mstrSourceDateColSuffix
                                    ElseIf SourceTypeCode.PBC.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                        drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + foundRows(index)("SourceName").ToString.Trim + mstrFilingDateColSuffix
                                    Else
                                        drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mdlDataHubBLLCommon.mstrSpaceIntend + foundRows(index)("SourceName").ToString.Trim + mstrSourceDateColSuffix
                                    End If
                                    drow("IsChild") = True
                                Else
                                    If SourceTypeCode.PBC.ToString = foundRows(index)("SourceTypeCode").ToString Or SourceTypeCode.RSH.ToString = foundRows(index)("SourceTypeCode").ToString Then
                                        drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + foundRows(index)("SourceName").ToString.Trim + mstrSourceColSuffix
                                    Else
                                        drow("Column List") = mdlDataHubBLLCommon.mstrTwoSpaces + mdlDataHubBLLCommon.mstrSpaceIntend + foundRows(index)("SourceName").ToString.Trim + mstrSourceColSuffix
                                    End If
                                    drow("IsChild") = True
                                End If
                                drow("ND") = foundRows(index)("IsND")
                                drow("NIL") = foundRows(index)("IsNIL")
                                drow("CategoryID") = foundRows(index)("ListingName")
                                drow("IsExpandable") = False
                                drow("SourceID") = foundRows(index)("ESourceID")
                                drow("EntityID") = foundRows(index)("EntityID")
                                drow("ListingID") = foundRows(index)("ListingID")
                                drow("ListingName") = foundRows(index)("ListingName")
                                drow("SourceTypeID") = GetSourceTypeId(foundRows(index)("SourceTypeCode").ToString)
                                drow("SortOrderID") = GetSortOrderID(foundRows(index)("ListingName"), dtColumnList)
                                drow("SumUpErrors") = False
                                drow("SortOrder") = GetSortOrderColumnList(foundRows(index)("SourceTypeCode").ToString)
                                drow("GroupID") = 1
                                dtColumnList.Rows.Add(drow)
                            Next
                        End If
                        '            End If
                    Next
                End If

                'distinctSourceName = view.ToTable(True, "EntityID", "SourceName") ', "ListingName", "ListingID")
                FilterQuery = "ListingName ='" + row("ListingName") + "'"
                foundRows = dtListingDate.Select(FilterQuery)
                If foundRows.Length > 0 Then
                    drow = dtColumnList.NewRow()
                    drow("ExpandCollapse") = DBNull.Value
                    drow("Show") = False
                    drow("Column List") = foundRows(0)("ColumnList").ToString '+ " " + drow1("ListingName")
                    drow("CategoryID") = foundRows(0)("ListingName")
                    drow("IsExpandable") = False
                    drow("IsChild") = False
                    drow("ListingID") = GetListingId(foundRows(0)("ListingName"), dtColumnList)
                    drow("ListingName") = foundRows(0)("ListingName")
                    drow("ListingDate") = foundRows(0)("ListingDate")
                    drow("SortOrderID") = GetSortOrderID(foundRows(0)("ListingName"), dtColumnList)
                    drow("IsDateColumn") = True
                    drow("SumUpErrors") = False
                    'drow("Source") = foundRows(0)("ListingDate")
                    drow("SortOrder") = GetSortOrderColumnList(SortOrderColumnList.DCL.ToString)
                    dtColumnList.Rows.Add(drow)
                End If
                'AddRecentDateColumn(dtListingDate, dtSourceType, dtColumnList)
            Next
            'SetSortOrder(dtColumnList)
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            dtListing = Nothing
            'dtSource = Nothing
            distinctESource = Nothing
            'distinctValues = Nothing
            foundRows = Nothing
            FilterQuery = Nothing
            drow = Nothing
        End Try
    End Sub

    Private Function CheckDDIColumnExist(ByVal lstrListingName As String, ByVal dtEntityTable As DataTable) As Boolean
        Dim foundRows() As DataRow
        Dim filterQuery As String
        filterQuery = "SourceTypeCode ='" + SourceTypeCode.DDI.ToString + "' And ESourceCode <>'" + DataSourceCode.DDALCOT.ToString + "' And ListingName ='" + lstrListingName + "'"
        foundRows = dtEntityTable.Select(filterQuery)
        If foundRows.Length > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dtSource"></param>
    ''' <param name="pstrESourceID"></param>
    ''' <param name="pstrListingID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetSourceTypeId(ByVal dtSource As DataTable, ByVal pstrESourceID As String, ByVal pstrListingID As String) As Integer
        Dim foundRows() As DataRow
        Dim FilterQuery As String
        Dim lintSourceTypeID As Integer = 0
        FilterQuery = "ESourceID ='" + pstrESourceID + "' And ListingID = '" + pstrListingID + "'"
        foundRows = dtSource.Select(FilterQuery)
        If foundRows.Length > 0 Then
            lintSourceTypeID = foundRows(0)("SourceTypeID")
            If SourceTypeCode.PRB = lintSourceTypeID Then
                Return SourceTypeCode.BKL
            End If
        End If
        Return lintSourceTypeID
    End Function

    ''' <summary>
    ''' Get ND values.
    ''' </summary>
    ''' <param name="dtSource"></param>
    ''' <param name="pstrESourceID"></param>
    ''' <param name="pstrListingID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetND(ByVal dtSource As DataTable, ByVal pstrESourceID As String, ByVal pstrListingID As String) As Integer
        Dim foundRows() As DataRow
        Dim FilterQuery As String
        Dim lintSourceTypeID As Integer = 0
        FilterQuery = "ESourceID ='" + pstrESourceID + "' And ListingID = '" + pstrListingID + "'"
        foundRows = dtSource.Select(FilterQuery)
        If foundRows.Length > 0 Then
            lintSourceTypeID = foundRows(0)("IsND")
        End If
        Return lintSourceTypeID
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dtSource"></param>
    ''' <param name="pstrESourceID"></param>
    ''' <param name="pstrListingID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetEntityID(ByVal dtSource As DataTable, ByVal pstrESourceID As String, ByVal pstrListingID As String) As Integer
        Dim foundRows() As DataRow
        Dim FilterQuery As String
        Dim lintSourceTypeID As Integer = 0
        FilterQuery = "ESourceID ='" + pstrESourceID + "' And ListingID = '" + pstrListingID + "'"
        foundRows = dtSource.Select(FilterQuery)
        If foundRows.Length > 0 Then
            lintSourceTypeID = foundRows(0)("EntityID")
        End If
        Return lintSourceTypeID
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dtSource"></param>
    ''' <param name="pstrESourceID"></param>
    ''' <param name="pstrListingID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetNIL(ByVal dtSource As DataTable, ByVal pstrESourceID As String, ByVal pstrListingID As String) As Integer
        Dim foundRows() As DataRow
        Dim FilterQuery As String
        Dim lintSourceTypeID As Integer = 0
        FilterQuery = "ESourceID ='" + pstrESourceID + "' And ListingID = '" + pstrListingID + "'"
        foundRows = dtSource.Select(FilterQuery)
        If foundRows.Length > 0 Then
            lintSourceTypeID = foundRows(0)("IsNIL")
        End If
        Return lintSourceTypeID
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dtColumnList"></param>
    ''' <remarks></remarks>
    Private Sub SetSortOrder(ByRef dtColumnList As DataTable)
        Dim view As New DataView(dtColumnList)
        Dim distinctValues As DataTable = view.ToTable(True, "ListingID")
        Dim FilterQuery As String
        Dim Excel() As DataRow
        For i As Integer = 0 To distinctValues.Rows.Count - 1
            If distinctValues.Rows(i)(0) IsNot DBNull.Value Then
                FilterQuery = "ListingID ='" + dtColumnList.Rows(i)("ListingID").ToString + "'"
                Excel = dtColumnList.Select(FilterQuery)
                If Excel.Length <> 0 Then
                    For Each ldrow As DataRow In Excel
                        ldrow("SortOrderID") = i + 1
                        mintSortOrder = i + 1
                    Next
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Add Current Suggested Rows.
    ''' </summary>
    ''' <param name="dtListing"></param>
    ''' <param name="dtGridColumnList"></param>
    ''' <remarks></remarks>
    Private Sub AddCurrentSuggestedRows(ByVal dtListing As DataTable, ByVal dtGridColumnList As DataTable)
        Dim lstrCurrent As String = mdlDataHubBLLCommon.mstrCurrentSuffix
        Dim lstrSuggested As String = mdlDataHubBLLCommon.mstrSuggestedFinalSuffix
        Dim lstrSpace As String = mdlDataHubBLLCommon.mstrSpaceIntend
        Dim drow As DataRow
        For i = 0 To dtListing.Rows.Count - 1
            For j = 0 To 1
                drow = dtGridColumnList.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                If j = 0 Then
                    drow("Column List") = lstrCurrent + " " + dtListing.Rows(i)("ListingName").ToString
                    drow("IsChild") = False
                Else
                    drow("Column List") = lstrSpace + lstrSuggested + " " + dtListing.Rows(i)("ListingName").ToString
                    drow("IsChild") = False
                End If
                drow("ND") = False
                drow("NIL") = False
                drow("CategoryID") = dtListing.Rows(i)("ListingName").ToString
                drow("IsExpandable") = False
                drow("IsCollapsed") = DBNull.Value
                drow("SortOrderID") = GetSortOrderID(dtListing.Rows(i)("ListingName").ToString, dtGridColumnList)
                drow("ListingID") = dtListing.Rows(i)("ListingID").ToString
                drow("ListingName") = dtListing.Rows(i)("ListingName").ToString
                drow("SortOrder") = GetSortOrderColumnList(SortOrderColumnList.CSC.ToString)
                If j = 0 Then
                    drow("Alpha Shortcuts") = "A"
                Else
                    drow("Alpha Shortcuts") = "S"
                End If
                drow("SumUpErrors") = False
                dtGridColumnList.Rows.Add(drow)
            Next
        Next
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="dtGridColumnList"></param>
    ''' <param name="dsColumnListEntities"></param>
    ''' <remarks></remarks>
    Private Sub GetColumnListDataHub(ByRef dtGridColumnList As DataTable, ByVal dsColumnListEntities As DataSet)
        CreateGridHeaderColumns(dtGridColumnList)

        'Add the Rows to grid that are expandable.
        AddParentRowsOfGrid(dtGridColumnList)

        'Collect data in table in Categories. So that it can easily be arranged.
        AddRowsOfAttributeSet1(dtGridColumnList)
        'Add rows of UpdatesandDDInfoColumnTitles category retrieved from db.
        AddRowsOfUpdateAndDDInfo(dtGridColumnList, _
                                 dsColumnListEntities.Tables(ColumnListCategoriesTables.UpdatesandDDInfoColumnTitles))

        'Add rows of RegistersBlanklists category retrieved from db.
        AddRowsOfRegBanklist(dtGridColumnList, _
                             dsColumnListEntities.Tables(ColumnListCategoriesTables.RegistersBlanklists))

        'Add rows of PreviousFinalisedListings category retrieved from db.
        AddRowsOfPreviousListingProjects(dtGridColumnList, _
                                         dsColumnListEntities.Tables(ColumnListCategoriesTables.PreviousFinalisedListings))
        AddRowsOfAttributeSet2(dtGridColumnList)
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetDataSourceAddByUser()
        Dim larrAllMissingColumnsDataHub(0) As String
        Dim lstDataSources As List(Of CurrentDataSources)
        Dim lclsColumnListManager As New ColumnListManager
        lstDataSources = lclsColumnListManager.GetCurrentDataSources(mintProjectID)
        If lstDataSources IsNot Nothing Then
            For Each lstSource As CurrentDataSources In lstDataSources
                If mstrAllColumnsDataHub.Contains(lstSource.SourceName.ToString) Then
                Else
                    mstCurrentDataSources.Add(lstSource)
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' We cannot hide the expandable rows. Check the rows that are visible on Hub Form else uncheck.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub CheckRowsVisibleOnHub()
        For Each ugRow As UltraGridRow In grdColumnList.Rows
            'We cannot hide the expandable rows. Check the rows that are visible on Hub Form else uncheck.
            If ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False Then
                If marrAllVisibleSourceNameCols.Contains(ugRow.GetCellValue(ugRow.Cells("Column List").Column).ToString.Trim) Then
                    ugRow.Cells("Show").Value = True
                Else
                    If marrAllVisibleSourceNameCols.Contains(ugRow.GetCellValue(ugRow.Cells("Column List").Column).ToString + mstrND) Or marrAllVisibleSourceNameCols.Contains(ugRow.GetCellValue(ugRow.Cells("Column List").Column).ToString + mstrNIL) Then
                        ugRow.Cells("Show").Value = True
                    Else
                        ugRow.Cells("Show").Value = False
                    End If
                End If
                If ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False And ugRow.GetCellValue(ugRow.Cells("CategoryID").Column) = ColumnListCategories.PFL.ToString Then
                    If marrAllVisibleSourceNameCols.Contains(ugRow.GetCellValue(ugRow.Cells("Source").Column).ToString) Then
                        ugRow.Cells("Show").Value = True
                    End If
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Check the expandable row if all the rows of Category are checked and set unchecked if one or more is unchecked.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetParentRowTrueIfAllChildTrue()
        Dim checkStatus As Boolean = False
        Try
            For Each row As UltraGridRow In grdColumnList.Rows
                If row.GetCellValue(row.Cells("IsExpandable").Column) = True And row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.AS1.ToString Then
                    checkStatus = SetCheckBoxAttributeSet1()
                    row.Cells("Show").Value = checkStatus

                End If
                If row.GetCellValue(row.Cells("IsExpandable").Column) = True And row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.UDI.ToString Then
                    checkStatus = SetCheckBoxUpdateAndDDInfo()
                    row.Cells("Show").Value = checkStatus
                End If
                If row.GetCellValue(row.Cells("IsExpandable").Column) = True And row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.RBC.ToString Then
                    checkStatus = SetCheckBoxRegBanklist()
                    row.Cells("Show").Value = checkStatus
                End If
                If row.GetCellValue(row.Cells("IsExpandable").Column) = True And row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.PFL.ToString Then
                    checkStatus = SetCheckBoxPreviousListingProjects()
                    row.Cells("Show").Value = checkStatus
                End If
                If row.GetCellValue(row.Cells("IsExpandable").Column) = True And row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.AS2.ToString Then
                    checkStatus = SetCheckBoxAttributeSet2()
                    row.Cells("Show").Value = checkStatus
                End If
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            checkStatus = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' If All the rows of Attribute Set 1 are checked than return True, So that Expandable row can be checked. Else Uncheck.
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private Function SetCheckBoxAttributeSet1() As Boolean
        For Each ugRow As UltraGridRow In grdColumnList.Rows
            If ugRow.GetCellValue(ugRow.Cells("CategoryID").Column) = ColumnListCategories.AS1.ToString And ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False Then
                If ugRow.Cells("Show").Text = "False" Then
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    ''' <summary>
    ''' If All the rows of Update and DD Info are checked than return True, So that Expandable row can be checked. Else Uncheck.
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private Function SetCheckBoxUpdateAndDDInfo() As Boolean
        For Each ugRow As UltraGridRow In grdColumnList.Rows
            If ugRow.GetCellValue(ugRow.Cells("CategoryID").Column) = ColumnListCategories.UDI.ToString And ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False Then
                If ugRow.GetCellText(ugRow.Cells("Show").Column).ToString = "False" Then
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    ''' <summary>
    ''' If All the rows of Register, Banklist and Others are checked than return True, So that Expandable row can be checked. Else Uncheck.
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private Function SetCheckBoxRegBanklist() As Boolean
        For Each ugRow As UltraGridRow In grdColumnList.Rows
            If ugRow.GetCellValue(ugRow.Cells("CategoryID").Column) = ColumnListCategories.RBC.ToString _
                And ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False Then
                If ugRow.GetCellText(ugRow.Cells("Show").Column).ToString = "False" Then
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    ''' <summary>
    ''' If All the rows of Previous projects listing are checked than return True, So that Expandable row can be checked. Else Uncheck.
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private Function SetCheckBoxPreviousListingProjects() As Boolean
        For Each ugRow As UltraGridRow In grdColumnList.Rows
            If ugRow.GetCellValue(ugRow.Cells("CategoryID").Column) = ColumnListCategories.PFL.ToString _
                And ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False Then
                If ugRow.Cells("Show").Text = "False" Then
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    ''' <summary>
    ''' If All the rows of Attribute Set 2 are checked than return True, So that Expandable row can be checked. Else Uncheck.
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private Function SetCheckBoxAttributeSet2() As Boolean
        For Each ugRow As UltraGridRow In grdColumnList.Rows
            If ugRow.GetCellValue(ugRow.Cells("CategoryID").Column) = ColumnListCategories.AS2.ToString And ugRow.GetCellValue(ugRow.Cells("IsExpandable").Column) = False Then
                If ugRow.GetCellText(ugRow.Cells("Show").Column) = "False" Then
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    ''' <summary>
    ''' Create the grid columns to insert the data in datatable. Datatable collects the data that will bind in Grid.
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Private Sub CreateGridHeaderColumns(ByRef dTable As DataTable)
        Dim cols As DataColumn
        Try
            For Each col As UltraGridColumn In grdColumnList.DisplayLayout.Bands(0).Columns
                cols = New DataColumn
                cols.ColumnName = col.Key
                cols.DataType = col.DataType
                dTable.Columns.Add(cols)
            Next
            If Not mblnDataHub Then
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("Alpha Shortcuts")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("ListingID")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("ListingName")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("SourceTypeID")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("GroupID")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("IsDateColumn")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("SumUpErrors")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("SortOrder")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("ListingDate")
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("SourceParent")

                grdColumnList.DisplayLayout.Bands(0).Columns("Alpha Shortcuts").Header.Appearance.ForeColor = Color.Black
                grdColumnList.DisplayLayout.Bands(0).Columns("SumUpErrors").Header.Appearance.ForeColor = Color.Black

                grdColumnList.DisplayLayout.Bands(0).Columns("SumUpErrors").Header.Caption = "Sum-Up" '.Appearance.ForeColor = Color.Black

                grdColumnList.DisplayLayout.Bands(0).Columns("ListingID").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("ListingName").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("SourceTypeID").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("IsDateColumn").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("SortOrder").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("ListingDate").Hidden = True

                dTable.Columns.Add("Alpha Shortcuts")
                dTable.Columns.Add("ListingID", GetType(Integer))
                dTable.Columns.Add("GroupID", GetType(Integer))
                dTable.Columns.Add("ListingName")
                dTable.Columns.Add("SourceTypeID")
                dTable.Columns.Add("IsDateColumn")
                dTable.Columns.Add("SumUpErrors", GetType(Boolean))
                dTable.Columns.Add("SortOrder", GetType(Integer))
                dTable.Columns.Add("ListingDate")
                dTable.Columns.Add("SourceParent", GetType(Boolean))

                grdColumnList.DisplayLayout.Bands(0).Columns("GroupID").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("IsDateColumn").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("Column List").Width = 330
                grdColumnList.DisplayLayout.Bands(0).Columns("SourceParent").Hidden = True
                grdColumnList.DisplayLayout.Bands(0).Columns("Alpha Shortcuts").Width = 60
                
                If mblnSumUp Then
                    grdColumnList.DisplayLayout.Bands(0).Columns("SumUpErrors").Header.VisiblePosition = grdColumnList.DisplayLayout.Bands(0).Columns("Show").Index + 1
                    Me.Width = grdColumnList.Width + 70
                Else
                    'Me.Width = grdColumnList.Width + 20
                    grdColumnList.DisplayLayout.Bands(0).Columns("SumUpErrors").Hidden = True
                End If
            Else
                grdColumnList.DisplayLayout.Bands(0).Columns.Add("SourceTypeCode")
                dTable.Columns.Add("SourceTypeCode")
                grdColumnList.DisplayLayout.Bands(0).Columns("SourceTypeCode").Hidden = True
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            cols = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add Parent Rows Of Grid FL
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <remarks></remarks>
    Private Sub AddParentRowsOfGridFL(ByVal DtListing As DataTable, ByRef dtColumnListData As DataTable)
        Dim drow As DataRow
        Dim lintCount As Integer
        Dim lintList As Integer = 0
        lintCount = DtListing.Rows.Count + 3
        Try
            For i = 0 To lintCount - 1
                drow = dtColumnListData.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                If i = 0 Or i > DtListing.Rows.Count Then
                    If i = 0 Then
                        drow("Column List") = marrGridRowsData(i)
                    ElseIf i = DtListing.Rows.Count + 1 Then
                        drow("Column List") = marrGridRowsData(3)
                    ElseIf i = DtListing.Rows.Count + 2 Then
                        drow("Column List") = marrGridRowsData(4)
                    End If
                Else
                    drow("Column List") = DtListing.Rows(lintList)("ListingName").ToString
                    drow("ListingName") = DtListing.Rows(lintList)("ListingName").ToString
                    drow("ListingID") = DtListing.Rows(lintList)("ListingID").ToString
                    lintList = lintList + 1
                End If
                drow("ND") = DBNull.Value
                drow("NIL") = DBNull.Value
                If i = 0 Or i > DtListing.Rows.Count Then
                    If i = 0 Then
                        'drow("Column List") = marrGridRowsData(i)
                        drow("CategoryID") = marrColumnListCategories(i)
                    ElseIf i = DtListing.Rows.Count + 1 Then
                        drow("CategoryID") = marrColumnListCategories(3)
                        'drow("Column List") = marrGridRowsData(3)
                    ElseIf i = DtListing.Rows.Count + 2 Then
                        drow("CategoryID") = marrColumnListCategories(4)
                        'drow("Column List") = marrGridRowsData(4)
                    End If
                Else
                    drow("CategoryID") = DtListing.Rows(lintList - 1)("ListingName").ToString
                End If
                If i = 0 Then
                    drow("GroupID") = 1
                End If
                drow("IsExpandable") = True
                drow("IsCollapsed") = DBNull.Value
                drow("SortOrderID") = i + 1
                'drow("SortOrder")
                dtColumnListData.Rows.Add(drow)
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
        End Try
    End Sub


    ''' <summary>
    ''' Add parent rows to grid. Parent rows actually are the expandable rows. Button click will expand and collapse the rows.
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <remarks></remarks>
    Private Sub AddParentRowsOfGrid(ByRef dTable As DataTable)
        Dim drow As DataRow
        Try
            For i = 0 To marrGridRowsData.Length - 1
                drow = dTable.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                drow("Column List") = marrGridRowsData(i)
                drow("ND") = DBNull.Value
                drow("NIL") = DBNull.Value
                drow("CategoryID") = marrColumnListCategories(i)
                drow("IsExpandable") = True
                drow("IsCollapsed") = DBNull.Value
                drow("SortOrderID") = i + 1
                dTable.Rows.Add(drow)
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add rows to grid. Attribute Set 1. Category 1.
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <remarks></remarks>
    Private Sub AddRowsOfAttributeSet1(ByRef dTable As DataTable)
        Dim drow As DataRow
        Try
            For i = 0 To marrAttributesSet1.Length - 1
                If Not mblnDataHub And i = 0 Then
                    Continue For
                End If
                drow = dTable.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                drow("Column List") = marrAttributesSet1(i)
                drow("ND") = DBNull.Value
                drow("NIL") = DBNull.Value
                drow("CategoryID") = marrColumnListCategories(mintStartIndex)
                drow("IsExpandable") = False
                drow("SourceID") = DBNull.Value
                drow("IsChild") = True
                drow("EntityID") = DBNull.Value
                drow("Source") = DBNull.Value
                drow("SortOrderID") = 1
                mintGroupID = 1
                If Not mblnDataHub Then
                    drow("GroupID") = mintGroupID
                End If
                dTable.Rows.Add(drow)
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add rows Of Update and DD Info. Also added the child row to Add the SourceDate in the grid with space.
    ''' Category 2
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <param name="ldtColumnListRows"></param>
    ''' <remarks></remarks>
    Private Sub AddRowsOfUpdateAndDDInfo(ByRef dTable As DataTable, ByVal ldtColumnListRows As DataTable)
        Dim drow As DataRow
        Dim drow1 As DataRow
        Try
            For i = 0 To ldtColumnListRows.Rows.Count - 1
                drow = dTable.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                drow("Column List") = ldtColumnListRows.Rows(i)("SourceName")
                drow("ND") = DBNull.Value
                drow("NIL") = DBNull.Value
                drow("CategoryID") = ldtColumnListRows.Rows(i)("CategoryID")
                drow("IsExpandable") = False
                drow("SourceID") = ldtColumnListRows.Rows(i)("ESourceID")
                drow("IsChild") = False
                drow("EntityID") = ldtColumnListRows.Rows(i)("EntityID")
                drow("Source") = DBNull.Value
                drow("SourceTypeCode") = ldtColumnListRows.Rows(i)("SourceTypeCode")
                drow("SortOrderID") = 2
                dTable.Rows.Add(drow)
                'Second row is used to add the child row in grid. Source Date. 
                If Not ldtColumnListRows.Rows(i)("SourceDate").ToString = DBNull.Value.ToString Then
                    drow1 = dTable.NewRow()
                    drow1("ExpandCollapse") = DBNull.Value
                    drow1("Edit") = DBNull.Value
                    drow1("Show") = False
                    drow1("Column List") = "    " + ldtColumnListRows.Rows(i)("SourceDate")
                    drow1("ND") = DBNull.Value
                    drow1("NIL") = DBNull.Value
                    drow1("CategoryID") = ldtColumnListRows.Rows(i)("CategoryID")
                    drow1("IsExpandable") = False
                    drow1("SourceID") = ldtColumnListRows.Rows(i)("ESourceID")
                    drow1("IsChild") = True
                    drow1("EntityID") = ldtColumnListRows.Rows(i)("EntityID")
                    drow1("Source") = DBNull.Value
                    drow("SourceTypeCode") = ldtColumnListRows.Rows(i)("SourceTypeCode")
                    drow1("SortOrderID") = 2
                    dTable.Rows.Add(drow1)
                End If
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
            drow1 = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add rows t0 datatable from sql table to bind the rows to grid. Adding the rows at a time if child rows exist.
    ''' Category 3
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <param name="ldtColumnListRows"></param>
    ''' <remarks></remarks>
    Private Sub AddRowsOfRegBanklist(ByRef dTable As DataTable, ByVal ldtColumnListRows As DataTable)
        Dim drow As DataRow
        Dim drow1 As DataRow
        Dim drow2 As DataRow
        Try
            For i = 0 To ldtColumnListRows.Rows.Count - 1
                drow = dTable.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                drow("Column List") = ldtColumnListRows.Rows(i)("SourceName")
                drow("ND") = ldtColumnListRows.Rows(i)("IsND")
                drow("NIL") = ldtColumnListRows.Rows(i)("IsNIL")
                drow("CategoryID") = ldtColumnListRows.Rows(i)("CategoryID")
                drow("IsExpandable") = False
                drow("SourceID") = ldtColumnListRows.Rows(i)("ESourceID")
                drow("IsChild") = False
                drow("EntityID") = ldtColumnListRows.Rows(i)("EntityID")
                drow("Source") = DBNull.Value
                drow("SourceTypeCode") = ldtColumnListRows.Rows(i)("SourceTypeCode")
                drow("SortOrderID") = 3
                dTable.Rows.Add(drow)
                'Second row is used to add the child row in grid.i.e. Date
                If Not ldtColumnListRows.Rows(i)("SourceDate").ToString = DBNull.Value.ToString Then
                    drow1 = dTable.NewRow()
                    drow1("ExpandCollapse") = DBNull.Value
                    drow1("Edit") = DBNull.Value
                    drow1("Show") = False
                    drow1("Column List") = "     " + ldtColumnListRows.Rows(i)("SourceDate")
                    drow1("ND") = DBNull.Value
                    drow1("NIL") = DBNull.Value
                    drow1("CategoryID") = ldtColumnListRows.Rows(i)("CategoryID")
                    drow1("IsExpandable") = False
                    drow1("SourceID") = ldtColumnListRows.Rows(i)("ESourceID")
                    drow1("IsChild") = True
                    drow1("EntityID") = ldtColumnListRows.Rows(i)("EntityID")
                    drow("SourceTypeCode") = ldtColumnListRows.Rows(i)("SourceTypeCode")
                    drow1("Source") = DBNull.Value
                    drow1("SortOrderID") = 3
                    dTable.Rows.Add(drow1)
                    'Third row is used to add the child row in grid.Source row
                    drow2 = dTable.NewRow()
                    drow2("ExpandCollapse") = DBNull.Value
                    drow2("Edit") = DBNull.Value
                    drow2("Show") = False
                    drow2("Column List") = "     " + ldtColumnListRows.Rows(i)("Sources")
                    drow2("ND") = DBNull.Value
                    drow2("NIL") = DBNull.Value
                    drow2("CategoryID") = ldtColumnListRows.Rows(i)("CategoryID")
                    drow2("IsExpandable") = False
                    drow2("SourceID") = ldtColumnListRows.Rows(i)("ESourceID")
                    drow2("IsChild") = True
                    drow("SourceTypeCode") = ldtColumnListRows.Rows(i)("SourceTypeCode")
                    drow2("EntityID") = ldtColumnListRows.Rows(i)("EntityID")
                    drow2("Source") = DBNull.Value
                    drow2("SortOrderID") = 3
                    dTable.Rows.Add(drow2)
                End If
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
            drow1 = Nothing
            drow2 = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add the rows to datatable of previous projects. 
    ''' Category 4
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <param name="ldtColumnListRows"></param>
    ''' <remarks></remarks>
    Private Sub AddRowsOfPreviousListingProjects(ByRef dTable As DataTable, ByVal ldtColumnListRows As DataTable)
        Dim drow As DataRow
        Try
            For i = 0 To ldtColumnListRows.Rows.Count - 1
                drow = dTable.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                drow("Column List") = ldtColumnListRows.Rows(i)("FormatListingName") 'ldtColumnListRows.Rows(i)("SourceName") 
                drow("ND") = DBNull.Value
                drow("NIL") = DBNull.Value
                drow("CategoryID") = ldtColumnListRows.Rows(i)("CategoryID")
                drow("IsExpandable") = False
                drow("SourceID") = DBNull.Value
                drow("IsChild") = True
                drow("EntityID") = DBNull.Value
                drow("Source") = ldtColumnListRows.Rows(i)("SourceName")
                If mblnDataHub Then
                    drow("SortOrderID") = 4
                Else
                    drow("SortOrderID") = GetSortOrderID(marrGridRowsData(3), dTable)
                    drow("SumUpErrors") = False
                End If
                dTable.Rows.Add(drow)
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add the rows of Last Category Attribute Set 2
    ''' </summary>
    ''' <param name="dTable"></param>
    ''' <remarks></remarks>
    Private Sub AddRowsOfAttributeSet2(ByRef dTable As DataTable)
        Dim drow As DataRow
        Try
            For i = 0 To marrAttributesSet2.Length - 1
                drow = dTable.NewRow()
                drow("ExpandCollapse") = DBNull.Value
                drow("Edit") = DBNull.Value
                drow("Show") = False
                drow("Column List") = marrAttributesSet2(i)
                drow("ND") = DBNull.Value
                drow("NIL") = DBNull.Value
                drow("CategoryID") = marrColumnListCategories(marrColumnListCategories.Length - 1)
                drow("IsExpandable") = False
                drow("SourceID") = DBNull.Value
                drow("IsChild") = True
                drow("EntityID") = DBNull.Value
                drow("Source") = DBNull.Value
                If mblnDataHub Then
                    drow("SortOrderID") = 5
                Else
                    drow("SortOrderID") = GetSortOrderID(marrGridRowsData(4), dTable)
                End If
                dTable.Rows.Add(drow)
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            drow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Default collapsed categories.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub DefaultCollapsedCategories()
        CheckCollapsedExpandRows(ColumnListCategories.AS1.ToString, False)
        CheckCollapsedExpandRows(ColumnListCategories.AS2.ToString, False)
        CheckCollapsedExpandRows(ColumnListCategories.PFL.ToString, True)
        CheckCollapsedExpandRows(ColumnListCategories.RBC.ToString, True)
        CheckCollapsedExpandRows(ColumnListCategories.UDI.ToString, True)
    End Sub

    ''' <summary>
    ''' Make a string of Collapsed Categories. and is used when user open the form again. 
    ''' String contain the categories that will collapse the categories when the form open again. 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetCollapsedCategories()
        Dim ldtGridData As DataTable
        Dim FilterQuery As String
        Dim Excel() As DataRow
        mstrCollapsedCategories = String.Empty
        ldtGridData = CType(grdColumnList.DataSource, DataTable)
        FilterQuery = "IsExpandable =" + True.ToString '+ '" And IsCollapsed = " + False.ToString
        Excel = ldtGridData.Select(FilterQuery)
        If Excel.Length <> 0 Then
            For Each row As DataRow In Excel
                If Not row("IsCollapsed") Then
                    If mstrCollapsedCategories = String.Empty Then
                        mstrCollapsedCategories = row("CategoryID").ToString
                    Else
                        If Not mstrCollapsedCategories.Contains(row("CategoryID").ToString) Then
                            mstrCollapsedCategories = mstrCollapsedCategories + "," + row("CategoryID").ToString
                        End If
                    End If
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="EntityID"></param>
    ''' <remarks></remarks>
    Private Sub CheckParentWithChildRow(ByVal EntityID As Integer)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue(row.Cells("IsExpandable").Column) = False And (row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.UDI.ToString _
                                                            Or row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.RBC.ToString) Then
                If row.GetCellValue(row.Cells("EntityID").Column) = EntityID And row.GetCellValue(row.Cells("IsChild").Column) = False Then
                    row.Cells("Show").Value = True
                End If
            End If
        Next
    End Sub

    ''' <summary>
    '''  Check the row that have same SourceID.
    ''' 'Check all the rows with same source id. and also make sure it is parent.
    ''' </summary>
    ''' <param name="SourceID"></param>
    ''' <remarks></remarks>
    Private Sub CheckRowsWithSameSourceName(ByVal SourceID As Integer)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = False And (row.GetCellValue("CategoryID") = ColumnListCategories.UDI.ToString _
                                                                    Or row.GetCellValue("CategoryID") = ColumnListCategories.RBC.ToString) Then
                If row.GetCellValue(row.Cells("SourceID").Column) = SourceID Then
                    row.Cells("Show").Value = True
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' If parent row unchecked, than uncheck its child.    
    ''' </summary>
    ''' <param name="SourceID"></param>
    ''' <remarks></remarks>
    Private Sub UncheckChildWithParentUncheck(ByVal EntityID As Integer)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue(row.Cells("IsExpandable").Column) = False And (row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.UDI.ToString _
                                                            Or row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.RBC.ToString) Then
                If row.GetCellValue("EntityID") = EntityID Then
                    row.Cells("Show").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' When user click the expand - collapse in the grid.Hide/show the grid rows to collapse and expand.ClickCellButton event.
    ''' </summary>
    ''' <param name="CategoryID"></param>
    ''' <remarks></remarks>
    Private Sub CollapseExpandGridRowsUsingCategory(ByVal CategoryID As Integer)
        If grdColumnList.Rows Is Nothing Then Exit Sub
        If grdColumnList.Rows.Count = 0 Then Exit Sub
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue(row.Cells("CategoryID").Column) = CategoryID.ToString And row.GetCellValue(row.Cells("IsExpandable").Column) = False Then
                If row.Hidden = False Then
                    row.Hidden = True
                Else
                    row.Hidden = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Collapse the expandable rows that are collapsed last time.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub CollapseExpandableRowsUsingCategory()
        If grdColumnList.Rows Is Nothing Then Exit Sub
        If grdColumnList.Rows.Count = 0 Then Exit Sub
        If mstrCollapsedCategories = String.Empty Then Exit Sub
        For Each row As UltraGridRow In grdColumnList.Rows
            If mstrCollapsedCategories.Contains(row.GetCellValue(row.Cells("CategoryID").Column).ToString) And row.GetCellValue(row.Cells("IsExpandable").Column) = True Then
                CheckCollapsedExpandRows(row.GetCellValue(row.Cells("CategoryID").Column), True)
            ElseIf Not mstrCollapsedCategories.Contains(row.GetCellValue(row.Cells("CategoryID").Column).ToString) And row.GetCellValue(row.Cells("IsExpandable").Column) = True Then
                CheckCollapsedExpandRows(row.GetCellValue(row.Cells("CategoryID").Column), False)
            End If
        Next
    End Sub

    ''' <summary>
    ''' 'Set the values true to expand the rows of category.and False to collapse the rows.
    ''' </summary>
    ''' <param name="CategoryID"></param>
    ''' <param name="Check"></param>
    ''' <remarks></remarks>
    Private Sub CheckGridRowsCategory(ByVal CategoryID As String, ByVal Check As Boolean)
        If grdColumnList.Rows Is Nothing Then Exit Sub
        If grdColumnList.Rows.Count = 0 Then Exit Sub
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue(row.Cells("CategoryID").Column) = CategoryID.ToString Then
                If Check = True Then
                    row.Cells("Show").Value = True
                Else
                    If row.GetCellValue(row.Cells("Column List").Column) = "Name" And row.GetCellValue(row.Cells("CategoryID").Column) = ColumnListCategories.AS1.ToString Then
                    Else
                        row.Cells("Show").Value = False
                    End If
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub UpdateStatusOfDataEntites()
        mdtUpdateStatusNDNIL = New DataTable
        mdtUpdateStatusNDNIL.Columns.Add("EntityID", GetType(Integer))
        mdtUpdateStatusNDNIL.Columns.Add("IsND", GetType(Boolean))
        mdtUpdateStatusNDNIL.Columns.Add("IsNIL", GetType(Boolean))
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetCheckedRowsWithColumnsOfHub() As String()
        Dim marrCompareBeforeExit(0) As String
        For Each lrow As UltraGridRow In grdColumnList.Rows
            If lrow.GetCellValue(lrow.Cells("Show").Column) = True And lrow.GetCellValue(lrow.Cells("IsExpandable").Column) = False Then
                marrCompareBeforeExit(marrCompareBeforeExit.Length - 1) = lrow.GetCellValue(lrow.Cells("Column List").Column).ToString.Trim
                ReDim Preserve marrCompareBeforeExit(marrCompareBeforeExit.Length)
            End If
        Next
        ReDim Preserve marrCompareBeforeExit(marrCompareBeforeExit.Length - 2)
        Return marrCompareBeforeExit
    End Function

    ''' <summary>
    ''' Make table which contain the rows whose ND/NIL values changed.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub AddColumnTodtAppendNDNIL()
        mdtAppendNDNIL = New DataTable
        'mdtAppendNDNIL.Columns.Add("OldSourceName", GetType(String))
        'mdtAppendNDNIL.Columns.Add("SourceName", GetType(String))
        mdtAppendNDNIL.Columns.Add("IsND", GetType(Boolean))
        mdtAppendNDNIL.Columns.Add("IsNIL", GetType(Boolean))
        mdtAppendNDNIL.Columns.Add("EntityID", GetType(Integer))
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="str"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ReturnColumnNameVisible(ByVal str As String) As String
        For Each strName As String In marrAllVisibleSourceNameCols
            If strName = str Or strName = str + mstrND Or strName = str + mstrNIL Then
                str = strName
                Exit For
            End If
        Next
        Return str
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ArrCheckedEntitiesReturnToHubForm() As String()
        'Add the columns for new source name.
        Dim row As DataRow
        Dim row1 As DataRow
        Try
            Array.Resize(marrAllReturnSourceNameCols, 1)
            'AddColumnTodtAppendNDNIL()
            'UpdateStatusOfDataEntites()
            For Each lrow As UltraGridRow In grdColumnList.Rows
                If lrow.GetCellValue("Show") = True And lrow.GetCellValue("IsExpandable") = False Then
                    If lrow.Cells("NIL").Hidden = False And lrow.Cells("ND").Hidden = False And lrow.GetCellValue("ND").ToString <> String.Empty Or lrow.GetCellValue("NIL").ToString <> String.Empty Then
                        If lrow.GetCellValue("NIL") = True Then
                            marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length - 1) = lrow.GetCellValue(lrow.Cells("Column List").Column).ToString.Trim
                        ElseIf lrow.GetCellValue("ND") = True Then
                            marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length - 1) = lrow.GetCellValue("Column List").ToString.Trim
                        Else
                            marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length - 1) = lrow.GetCellValue("Column List").ToString.Trim
                            'row = mdtAppendNDNIL.NewRow()
                        End If
                    Else
                        If lrow.GetCellValue(lrow.Cells("CategoryID").Column) = ColumnListCategories.PFL.ToString And lrow.GetCellValue("IsExpandable") = False Then
                            marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length - 1) = lrow.GetCellValue(lrow.Cells("Source").Column).ToString.Trim
                        Else
                            marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length - 1) = lrow.GetCellValue("Column List").ToString.Trim
                        End If
                    End If
                    ReDim Preserve marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length)
                End If
            Next
            ReDim Preserve marrAllReturnSourceNameCols(marrAllReturnSourceNameCols.Length - 2)
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            row = Nothing
            row1 = Nothing
        End Try
        Return marrAllReturnSourceNameCols
    End Function
#End Region

#Region "Events"

    ''' <summary>
    ''' 'When user click the expand - collapse in the grid.Hide/show the grid rows to collapse and expand.ClickCellButton event.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdColumnList_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grdColumnList.InitializeLayout
        Dim lToolTipInfoAppereance As Appearance

        If mblnDataHub Then
            e.Layout.ViewStyleBand = ViewStyleBand.Horizontal
            e.Layout.Bands(0).SortedColumns.Add("SortOrderID", False, True)
            e.Layout.Rows.ExpandAll(False)
            e.Layout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False

            With e.Layout
                With .Override
                    .BorderStyleRow = UIElementBorderStyle.None
                    .BorderStyleCell = UIElementBorderStyle.None
                End With
            End With
        Else

            'e.Layout.Bands(0).Columns("Alpha Shortcuts").Header.Enabled = False
            ''e.Layout.Bands(0).Override.colu.Columns("Alpha Shortcuts").Header.Enabled = False
            'e.Layout.Bands(0).Columns("Alpha Shortcuts").Header.Appearance.ForeColorDisabled = Color.Black
            e.Layout.Bands(0).Columns("Alpha Shortcuts").SortIndicator = SortIndicator.Disabled
            e.Layout.ViewStyleBand = ViewStyleBand.Horizontal
            e.Layout.Bands(0).SortedColumns.Add("GroupID", False, True)
            e.Layout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False
            'e.Layout.Override..Appearance.BorderColor = Color.Black
            ' e.Layout.Appearance.BorderColor3DBase = Color.Black
            'With e.Layout
            '    With .Override
            '        .BorderStyleRow = UIElementBorderStyle.None
            '        .BorderStyleCell = UIElementBorderStyle.None
            '    End With
            'End With
        End If

        Dim values(3) As Integer
        CommonCustomControls.IsValidString(StyleManager.GetStyle("DE_GroupHeader_BackColor"), values)
        Dim lGridBackColorAppereance As Infragistics.Win.Appearance = e.Layout.Appearances.Add("ExpandableRowsBackColor")
        lGridBackColorAppereance.BackColor = Color.FromArgb(values(0), values(1), values(2))

        CommonCustomControls.IsValidString(StyleManager.GetStyle("FormBackColor"), values)
        Dim lGridFormBackColorAppereance As Infragistics.Win.Appearance = e.Layout.Appearances.Add("ChildExpandableRowsBackColor")
        lGridFormBackColorAppereance.BackColor = Color.FromArgb(values(0), values(1), values(2))

        lToolTipInfoAppereance = e.Layout.Appearances.Add("ToolTipInfo")
        lToolTipInfoAppereance.BackColor = Color.FromArgb(246, 214, 115)

    End Sub

    ''' <summary>
    ''' UltraWinGrid event Initialize row.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdColumnList_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdColumnList.InitializeRow
        Dim values(3) As Integer
        If e.ReInitialize = False Then
            If e.Row.Cells IsNot Nothing Then
                e.Row.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle
                If e.Row.GetCellValue(e.Row.Cells("IsExpandable").Column) = True Then
                    e.Row.Appearance.BackColor = grdColumnList.DisplayLayout.Appearances("ExpandableRowsBackColor").BackColor
                    e.Row.Cells("Edit").Hidden = True
                    e.Row.Cells("Edit").CellDisplayStyle = CellDisplayStyle.PlainText
                    e.Row.Cells("ND").Style = ColumnStyle.Image
                    e.Row.Cells("NIL").Style = ColumnStyle.Image
                    e.Row.Cells("ExpandCollapse").Style = ColumnStyle.Image
                    If Not mblnDataHub Then
                        If e.Row.Cells("Column List").Value = marrGridRowsData(0).ToString Then
                            e.Row.Cells("Show").Activation = Activation.Disabled
                        End If
                        e.Row.Cells("Alpha Shortcuts").Activation = Activation.Disabled
                        e.Row.Cells("SumUpErrors").Hidden = True
                    End If
                Else
                    e.Row.Appearance.BackColor = grdColumnList.DisplayLayout.Appearances("ChildExpandableRowsBackColor").BackColor

                    'Disable the field 'Name'and markded as true.
                    If mblnDataHub Then
                        If e.Row.GetCellValue(e.Row.Cells("Column List").Column) = "Name" And e.Row.GetCellValue(e.Row.Cells("CategoryID").Column) = ColumnListCategories.AS1.ToString Then
                            e.Row.Cells("Show").Value = True
                            e.Row.Cells("Show").Activation = Activation.Disabled
                        End If
                        ' Hide the rows for all the rows except category is 3.Hide the ND and NIL.
                        If e.Row.GetCellValue(e.Row.Cells("CategoryID").Column) = ColumnListCategories.RBC.ToString Or e.Row.GetCellValue("SortOrderID") = 3 Then
                            If e.Row.GetCellValue(e.Row.Cells("IsChild").Column) = True Then
                                e.Row.Cells("ND").Value = DBNull.Value
                                e.Row.Cells("NIL").Value = DBNull.Value
                                e.Row.Cells("ND").Style = ColumnStyle.Image
                                e.Row.Cells("NIL").Style = ColumnStyle.Image
                            Else
                                e.Row.Cells("ND").CellDisplayStyle = CellDisplayStyle.Default
                                e.Row.Cells("NIL").CellDisplayStyle = CellDisplayStyle.Default
                            End If
                        Else
                            e.Row.Cells("ND").Style = ColumnStyle.Image
                            e.Row.Cells("NIL").Style = ColumnStyle.Image
                        End If
                    Else
                        e.Row.Band.Layout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Solid
                        'e.Row.Band.Layout.Override.FixedCellSeparatorColor = Color.White
                        'e.Row.Band.Layout.Appearance.BorderColor = Color.White
                        e.Row.Band.Layout.Override.CellAppearance.BorderColor = Color.Black
                        e.Row.Band.Layout.Override.RowAppearance.BorderColor = Color.Black
                        If e.Row.GetCellValue("IsDateColumn") IsNot DBNull.Value Then
                            If e.Row.GetCellValue("IsDateColumn") Then
                                e.Row.Cells("ND").Style = ColumnStyle.Image
                                e.Row.Cells("NIL").Style = ColumnStyle.Image
                            End If
                        End If

                        If e.Row.GetCellValue("Column List").ToString.Trim.Equals(mdlDataHubBLLCommon.mstrSuggestedFinalListingColPrefix + e.Row.GetCellValue("ListingName")) Then
                            e.Row.Cells("SumUpErrors").Style = ColumnStyle.Image
                            e.Row.Cells("SumUpErrors").Hidden = True
                        End If

                        If marrColumnListCategories.Contains(e.Row.GetCellValue("CategoryID")) Then
                            e.Row.Cells("Edit").Hidden = True
                            e.Row.Cells("Edit").CellDisplayStyle = CellDisplayStyle.PlainText
                            e.Row.Cells("ND").Style = ColumnStyle.Image
                            e.Row.Cells("NIL").Style = ColumnStyle.Image
                            If e.Row.GetCellValue("CategoryID").ToString.Equals("AS1") Or e.Row.GetCellValue("CategoryID").ToString.Equals("AS2") Then
                                e.Row.Cells("SumUpErrors").Style = ColumnStyle.Image
                                e.Row.Cells("SumUpErrors").Hidden = True
                            End If
                        End If
                        If e.Row.GetCellValue("SourceTypeID") IsNot DBNull.Value And e.Row.GetCellValue("IsChild") IsNot DBNull.Value And e.Row.GetCellValue("IsDateColumn") Is DBNull.Value Then
                            If (e.Row.GetCellValue("SourceTypeID") = SourceTypeCode.RGT Or e.Row.GetCellValue("SourceTypeID") = SourceTypeCode.BKL Or _
                                e.Row.GetCellValue("SourceTypeID") = SourceTypeCode.PRB Or e.Row.GetCellValue("SourceTypeID") = SourceTypeCode.RSH Or _
                                e.Row.GetCellValue("SourceTypeID") = SourceTypeCode.PBC) And e.Row.GetCellValue("IsChild") = False Then
                                If e.Row.GetCellValue("SourceID") IsNot DBNull.Value Then
                                    e.Row.Cells("ND").CellDisplayStyle = CellDisplayStyle.Default
                                    e.Row.Cells("NIL").CellDisplayStyle = CellDisplayStyle.Default
                                Else
                                    e.Row.Cells("ND").Style = ColumnStyle.Image
                                    e.Row.Cells("NIL").Style = ColumnStyle.Image
                                End If
                            Else
                                e.Row.Cells("Edit").Hidden = True
                                e.Row.Cells("Edit").CellDisplayStyle = CellDisplayStyle.PlainText
                                e.Row.Cells("ND").Style = ColumnStyle.Image
                                e.Row.Cells("NIL").Style = ColumnStyle.Image
                            End If
                        End If
                        If e.Row.GetCellValue("Alpha Shortcuts") IsNot DBNull.Value Then
                            If e.Row.GetCellValue("Alpha Shortcuts").ToString = "A" Or e.Row.GetCellValue("Alpha Shortcuts").ToString = "S" Then
                                e.Row.Cells("ND").Style = ColumnStyle.Image
                                e.Row.Cells("NIL").Style = ColumnStyle.Image
                                e.Row.Cells("Alpha Shortcuts").Activation = Activation.Disabled
                            End If
                        End If
                        If e.Row.GetCellValue("CategoryID") IsNot DBNull.Value And e.Row.GetCellValue("IsChild") IsNot DBNull.Value Then
                            If Not marrColumnListCategories.Contains(e.Row.GetCellValue("CategoryID")) And e.Row.GetCellValue("IsChild") = False _
                                And e.Row.GetCellValue("IsExpandable") = False Then
                                e.Row.Cells("Alpha Shortcuts").Column.CellClickAction = CellClickAction.Edit
                                e.Row.Cells("Alpha Shortcuts").Appearance.BackColor = Color.White
                                e.Row.Cells("Alpha Shortcuts").Column.MaskInput = "A"
                                e.Row.Cells("Alpha Shortcuts").Column.PromptChar = ""
                                e.Row.Cells("SumUpErrors").Style = ColumnStyle.CheckBox
                            Else
                                If marrColumnListCategories.Contains(e.Row.GetCellValue("CategoryID")) And e.Row.GetCellValue("CategoryID").ToString.Equals(marrColumnListCategories(3).ToString) Then
                                Else
                                    e.Row.Cells("SumUpErrors").Activation = Activation.Disabled
                                    e.Row.Cells("SumUpErrors").Value = DBNull.Value
                                End If
                                e.Row.Cells("Alpha Shortcuts").Activation = Activation.Disabled
                                e.Row.Cells("SumUpErrors").Style = ColumnStyle.CheckBox
                            End If
                        Else
                            e.Row.Cells("Alpha Shortcuts").Activation = Activation.Disabled
                            e.Row.Cells("SumUpErrors").Value = DBNull.Value
                            e.Row.Cells("SumUpErrors").Style = ColumnStyle.Image
                            e.Row.Cells("SumUpErrors").Activation = Activation.Disabled
                        End If
                        If e.Row.Cells("EntityID").Value Is DBNull.Value Then
                            e.Row.Cells("ND").Style = ColumnStyle.Image
                            e.Row.Cells("NIL").Style = ColumnStyle.Image
                            'e.Row.Cells("Alpha Shortcuts").Activation = Activation.Disabled
                            'With e.Row.Cells("Column List").Band.Layout
                            '    With .Override
                            '        .BorderStyleRow = UIElementBorderStyle.None
                            '        .BorderStyleCell = UIElementBorderStyle.None
                            '    End With
                            'End With
                        End If
                        If e.Row.Cells("Column List").Value = "Name" Then
                            e.Row.Cells("Show").Activation = Activation.Disabled
                        End If

                        'If e.Row.GetCellValue("CategoryID") IsNot DBNull.Value And e.Row.GetCellValue("IsExpandable") IsNot DBNull.Value Then
                        '    If e.Row.GetCellValue("CateroryID").ToString = marrColumnListCategories(3).ToString And e.Row.GetCellValue("IsExpandable") = False Then
                        '        e.Row.Cells("SumUpErrors").Style = ColumnStyle.CheckBox
                        '        e.Row.Cells("SumUpErrors").Activation = Activation.AllowEdit
                        '    End If
                        'End If
                        'e.Row.Cells("Alpha Shortcuts").Style = ColumnStyle.Edit
                    End If
                End If
            End If
        End If
    End Sub

    Private Function GetGroupShortcutID(ByVal lintSourceTypeID As Integer) As String
        Dim lintGroupID As String
        If SourceTypeCode.BKL = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.BKL.ToString
        ElseIf SourceTypeCode.DDI = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.DDI.ToString
        ElseIf SourceTypeCode.PBC = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.PBC.ToString
        ElseIf SourceTypeCode.PRB = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.PRB.ToString
        ElseIf SourceTypeCode.RGT = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.RGT.ToString
        ElseIf SourceTypeCode.RSH = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.RSH.ToString
        ElseIf SourceTypeCode.UPD = lintSourceTypeID Then
            lintGroupID = DataSourceGroup.UPD.ToString
        Else
            lintGroupID = DataSourceGroup.OTH.ToString
        End If
        Return lintGroupID
    End Function

    ''' <summary>
    ''' Save the expand collapse state and columns newwly visible.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Dim nextRole As String
        Dim mclsColumnListManager As New ColumnListManager
        Dim lstrHiddenColumns As String = String.Empty
        Dim larrStr() As String
        Dim larrVisibleCategories(0) As String
        Dim dtGridData As DataTable
        Dim filterQuery As String
        Dim drow() As DataRow
        mdicShortCutColumn = New Dictionary(Of String, String)
        Try
            'GetCollapsedCategories contains the collapsed category id.when user return again to screen  , this maintain the expanded mode.
            grdColumnList.Update()
            grdColumnList.UpdateData()
            GetCollapsedCategories()
            If mblnDataHub Then
                'Make the array of columns that are marked true and visible on DataHub Screen.
                marrAllReturnSourceNameCols = ArrCheckedEntitiesReturnToHubForm()
                'Create XML of ND and NIL to update the data in database.
                InsertXMLToDB()
                If marrAllReturnSourceNameCols.Length <> marrAllVisibleSourceNameCols.Length Then
                    MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_UPDATED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    For Each nextRole In marrAllReturnSourceNameCols
                        If Array.IndexOf(marrAllVisibleSourceNameCols, nextRole, 0) = -1 Then
                            MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_UPDATED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                            Exit For
                        End If
                    Next
                End If
                'If datacha5nged after open the form..show message 'Updated successfully.'            
                'is used to close the form.after saving the changes.
            Else
                Dim sbXML As New StringBuilder
                Dim sbXML1 As New StringBuilder
                'Dim lintgroupID As Integer = 0
                sbXML.Append("<Root>")
                sbXML1.Append("<Root>")
                larrStr = marrVisibleParentCols
                For Each ugRow As UltraGridRow In grdColumnList.Rows
                    If ugRow.GetCellValue("Show") = False Then
                        If lstrHiddenColumns.Length = 0 Then
                            lstrHiddenColumns = ugRow.GetCellValue("Column List").ToString.Trim
                        Else
                            lstrHiddenColumns = lstrHiddenColumns + mdlDataHubBLLCommon.mstrSOFColPrefix + ugRow.GetCellValue("Column List").ToString.Trim
                        End If
                    End If
                    If (ugRow.GetCellValue("IsExpandable") And ugRow.GetCellValue("Show")) Or (ugRow.GetCellValue("IsExpandable") And marrColumnListCategories.Contains(ugRow.GetCellValue("CategoryID"))) Then
                        larrVisibleCategories(larrVisibleCategories.Length - 1) = ugRow.GetCellValue("CategoryID").ToString.Trim
                        ReDim Preserve larrVisibleCategories(larrVisibleCategories.Length)
                    End If

                    If ugRow.GetCellValue("IsExpandable") = False And marrColumnListCategories.Contains(ugRow.GetCellValue("CategoryID")) = False Then
                        If Not ugRow.Cells("Alpha Shortcuts").Activation = Activation.Disabled Then
                            If Not ugRow.Cells("Alpha Shortcuts").Value.ToString.Trim.Equals(String.Empty) Then
                                If ugRow.GetCellValue("EntityID") IsNot DBNull.Value Then
                                    sbXML.Append("<Row EntityID=""" & ugRow.GetCellValue("EntityID").ToString().Replace("'", "&apos;").Replace("&", "&amp;") _
                                    .Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                     "Shortcut=""" & ugRow.Cells("Alpha Shortcuts").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " &
                                     "/>")
                                    sbXML.Append(vbNewLine)
                                    mdicShortCutColumn.Add(ugRow.Cells("Column List").Value.ToString.Trim, ugRow.Cells("Alpha Shortcuts").Value)
                                Else
                                    If ugRow.GetCellValue("SourceID") IsNot DBNull.Value Then
                                        sbXML1.Append("<Row GroupCode=""" & DataSourceGroup.DDA.ToString.Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                        "ListingID=""" & ugRow.Cells("ListingID").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                        "ESourceID=""" & ugRow.Cells("SourceID").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                        "Shortcut=""" & ugRow.Cells("Alpha Shortcuts").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " &
                                      "/>")
                                    Else
                                        If ugRow.GetCellValue("SourceTypeID") IsNot DBNull.Value Then
                                            sbXML1.Append("<Row GroupCode=""" & GetGroupShortcutID(ugRow.GetCellValue("SourceTypeID")).ToString.Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                                "ListingID=""" & ugRow.Cells("ListingID").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                                "ESourceID=""" & ugRow.Cells("SourceID").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                                 "Shortcut=""" & ugRow.Cells("Alpha Shortcuts").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " &
                                                 "/>")
                                            sbXML1.Append(vbNewLine)
                                            mdicShortCutColumn.Add(ugRow.Cells("Column List").Value.ToString.Trim, ugRow.Cells("Alpha Shortcuts").Value)
                                        Else
                                            If ugRow.GetCellValue("IsDateColumn") IsNot DBNull.Value Then
                                                'lintgroupID = DataSourceGroup.OTH
                                                sbXML1.Append("<Row GroupCode=""" & DataSourceGroup.OTH.ToString.Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                                "ListingID=""" & ugRow.Cells("ListingID").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                                "ESourceID=""" & ugRow.Cells("SourceID").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                                 "Shortcut=""" & ugRow.Cells("Alpha Shortcuts").Value.ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " &
                                                 "/>")
                                                sbXML1.Append(vbNewLine)
                                                mdicShortCutColumn.Add(ugRow.Cells("Column List").Value.ToString.Trim, ugRow.Cells("Alpha Shortcuts").Value)
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        Else
                            If ugRow.Cells("Alpha Shortcuts").Value IsNot DBNull.Value Then
                                mdicShortCutColumn.Add(ugRow.Cells("Column List").Value.ToString.Trim, ugRow.Cells("Alpha Shortcuts").Value)
                            End If
                        End If
                    End If
                Next
                sbXML.Append("</Root>")
                sbXML1.Append("</Root>")
                mclsColumnListManager.InsertShortCut(mintProjectID, sbXML1.ToString)
                mclsColumnListManager.InsertShortCutEntity(mintProjectID, sbXML.ToString)
                dtGridData = CType(grdColumnList.DataSource, DataTable)
                For Each lstr As String In larrVisibleCategories
                    filterQuery = "CategoryID = '" + lstr + "' And Show = True"
                    drow = dtGridData.Select(filterQuery)
                    If drow.Length > 0 Then
                        For Each dtRow As DataRow In drow
                            If marrColumnListCategories.Contains(lstr) Then
                                If lstr = "PFL" And dtRow("IsExpandable") = False Then
                                    marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("Source").ToString.Trim
                                    ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                Else
                                    If dtRow("IsExpandable") = False Then
                                        marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("Column List").ToString.Trim
                                        ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                    End If
                                End If
                            Else
                                If dtRow("IsExpandable") = False Then
                                    If dtRow("SourceTypeID") IsNot DBNull.Value Then
                                        If dtRow("EntityID") Is DBNull.Value Then
                                            CheckVisibilitySourceType(dtRow, drow) 'Then ' dtRow("SourceTypeID"), dtRow("ListingName")) Then
                                            marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("Column List").ToString.Trim
                                            ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                            'End If
                                        Else
                                            If dtRow("SourceTypeID") = SourceTypeCode.RSH Or dtRow("SourceID") = DataSourceCode.DDALCOT Or dtRow("SourceTypeID") = SourceTypeCode.PBC Then
                                                marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("Column List").ToString.Trim
                                                ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                            End If
                                        End If
                                    Else
                                        If dtRow("Column List") = mstrCurrentSuffix + " " + lstr Then
                                            marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("Column List").ToString.Trim
                                            ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                        ElseIf dtRow("Column List").ToString.Trim = mstrSuggestedFinalSuffix + " " + lstr Then
                                            If CheckVisibilityCurrentListing(lstr) Then
                                                marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("Column List").ToString.Trim
                                                ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                            End If
                                        ElseIf dtRow("IsDateColumn") IsNot DBNull.Value Then
                                            If dtRow("IsDateColumn") Then
                                                marrVisibleParentCols(marrVisibleParentCols.Length - 1) = dtRow("ListingDate").ToString.Trim
                                                ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        Next
                    End If
                Next
                ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length - 1)
                mclsColumnListManager.HiddenColumnsFL(mintProjectID, lstrHiddenColumns)
                InsertXMLToDB()
                If mdtAppendNDNIL IsNot Nothing Then
                    If mdtAppendNDNIL.Rows.Count > 0 Then
                        MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_UPDATED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                    End If
                ElseIf CheckHiddenColumnsFL() = False And mdicAlphaShortCut IsNot Nothing Then
                    MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_UPDATED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
                If mblnSumUp Then
                    dtGridData = CType(grdColumnList.DataSource, DataTable)
                    filterQuery = "SumUpErrors = True"
                    drow = dtGridData.Select(filterQuery)
                    For Each row As DataRow In drow
                        If marrColumnListCategories.Contains(row("CategoryID")) Then
                            mlstSumUpErrors.Add(row("Source").ToString.Trim)
                        Else
                            If row("IsDateColumn").ToString = "True" Then
                                mlstSumUpErrors.Add(row("ListingDate").ToString.Trim)
                            Else
                                mlstSumUpErrors.Add(row("Column List").ToString.Trim)
                            End If
                        End If
                    Next
                End If
            End If
            mIsOkClicked = True
            Me.Close()
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            nextRole = Nothing
            mclsColumnListManager = Nothing
        End Try
    End Sub

    Private Sub CheckVisibilitySourceType(ByVal row As DataRow, ByVal rows() As DataRow)
        Dim dtGridData As New DataTable
        Dim filterQuery As String
        Dim foundRows() As DataRow
        dtGridData = CType(grdColumnList.DataSource, DataTable).Clone()
        For Each drow As DataRow In rows
            dtGridData.ImportRow(drow)
        Next
        filterQuery = "SortOrder ='" + row("SortOrder").ToString + "'"
        foundRows = dtGridData.Select(filterQuery)
        For Each row1 As DataRow In foundRows
            If row("SortOrderID") = SourceTypeCode.DDI Then
                If row("SourceID") IsNot DBNull.Value Then
                    If row("SourceID") <> DataSourceCode.DDALCOT Then
                        marrVisibleParentCols(marrVisibleParentCols.Length - 1) = row1("Column List").ToString.Trim
                        ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                    End If
                Else
                    marrVisibleParentCols(marrVisibleParentCols.Length - 1) = row1("Column List").ToString.Trim
                    ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
                End If
            Else
                marrVisibleParentCols(marrVisibleParentCols.Length - 1) = row1("Column List").ToString.Trim
                ReDim Preserve marrVisibleParentCols(marrVisibleParentCols.Length)
            End If

            'If strSourceTypeCode = SourceTypeCode.DDI Then
            '    If row("SourceID") IsNot DBNull.Value Then
            '        If row("SourceID") = DataSourceCode.DDALCOT Then
            '            Return True
            '        End If
            '    Else
            '        For Each drow As DataRow In foundRows
            '            If drow("SourceID") IsNot DBNull.Value Then
            '                If drow("SourceID") <> DataSourceCode.DDALCOT Then
            '                    Return True
            '                End If
            '            End If
            '        Next
            '        'Return True
            '    End If
            'Else
            '    If row("EntityID") Is DBNull.Value Then
            '        If row("IsChild") Is DBNull.Value Then
            '            row("IsChild") = False
            '        End If
            '        If row("SourceTypeID") IsNot DBNull.Value And row("IsChild") = False Then
            '            Return True
            '        End If

            '    End If
            'End If
        Next
    End Sub

    Private Function CheckVisibilityCurrentListing(ByVal strListingName As String) As Boolean
        Dim blnShow As Boolean = False
        Dim dtGridData As New DataTable
        Dim filterQuery As String
        Dim foundRows() As DataRow
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        filterQuery = "[Column List] ='" + mstrCurrentSuffix + " " + strListingName + "' And Show = True"
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length > 0 Then
            Return True
        End If
        Return blnShow
    End Function

    Private Function CheckChangeFL() As Boolean
        If mdtAppendNDNIL IsNot Nothing Then
            ReturnColumnNameVisible(True)
        End If
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub InsertXMLToDB()
        Dim strXML As String = String.Empty
        Dim mclsColumnListManager As New ColumnListManager
        If mdtAppendNDNIL IsNot Nothing Then
            If mdtAppendNDNIL.Rows.Count > 0 Then
                strXML = CreateXML(mdtAppendNDNIL).ToString
                If strXML <> String.Empty Then
                    mclsColumnListManager.UpdateColumnListEntities(strXML)
                End If
            End If
        End If
    End Sub

    ''' <summary>
    ''' Close form.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    ''' <summary>
    ''' Check if column is locked in DE.
    ''' </summary>
    ''' <param name="lstrCategoryId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CheckLockedColumnInHub(ByVal lstrCategoryId As String) As Boolean
        Dim ldtGridData As DataTable
        Dim FilterQuery As String
        Dim Excel() As DataRow
        mstrCollapsedCategories = String.Empty
        ldtGridData = CType(grdColumnList.DataSource, DataTable)
        FilterQuery = "IsExpandable <>'" + True.ToString + "' And CategoryID = '" + lstrCategoryId + "'"
        Excel = ldtGridData.Select(FilterQuery)
        If Excel.Length <> 0 Then
            If mstCurrentDataSourcesDataHub.Count = 0 Then Return False
            If mstCurrentDataSourcesDataHub(0).SourceName Is Nothing Then Return False
            For Each lobjCurrentDataSource As CurrentDataSources In mstCurrentDataSourcesDataHub
                For Each row As DataRow In Excel
                    If (lobjCurrentDataSource.SourceName.Equals(row("Column List").ToString.Trim)) _
                        AndAlso lobjCurrentDataSource.AccessStatus = SourceAccessbility.Locked.ToString Then
                        Return False
                    End If
                Next
            Next
        End If
        Return True
    End Function

    ''' <summary>
    ''' Check ND/NIL Status DE.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CheckInvalidValue(ByVal lstrCategoryCode As String) As Boolean
        'Dim ldtGridData As DataTable
        'Dim FilterQuery As String
        'Dim Excel() As DataRow
        Dim pblnIsInvalidValue As Boolean = True
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.Cells("CategoryID").Value Is DBNull.Value Then Continue For
            If row.Cells("CategoryID").Value.ToString <> lstrCategoryCode Then Continue For
            RaiseEvent CheckNDNILStatus(Nothing, True, row.Cells("Column List").ToString.Trim, pblnIsInvalidValue)
            If pblnIsInvalidValue = False Then
                Return False
            End If
        Next
        mstrCollapsedCategories = String.Empty
        'ldtGridData = CType(grdColumnList.DataSource, DataTable)
        'FilterQuery = "CategoryID ='" + lstrCategoryCode + "'"
        'Excel = ldtGridData.Select(FilterQuery)
        'If Excel.Length <> 0 Then
        '    For Each row As DataRow In Excel
        '        RaiseEvent CheckNDNILStatus(Nothing, True, row("Column List"), pblnIsInvalidValue)
        '        If pblnIsInvalidValue = False Then
        '            Return False
        '        End If
        '    Next
        'End If
        Return True
    End Function

    ''' <summary>
    ''' Event fires when user check or uncheck the in the fields.
    ''' </summary>
    ''' <param name="sender"></param>Fmess
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdColumnList_CellChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles grdColumnList.CellChange
        If e.Cell Is Nothing Then Exit Sub
        ' If IsExpandable is checked.Than Check all the fields of that category.
        'If mblnDataHub Then
        '    If e.Cell.Row.GetCellValue("IsExpandable") = True And e.Cell.Column.Header.Caption = "Show" Then
        '        If CheckInvalidValue() = False And e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.RBC.ToString Then
        '            MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_CHANGE"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
        '            e.Cell.CancelUpdate()
        '            Exit Sub
        '        End If
        '        If CheckLockedColumnInHub(e.Cell.Row.GetCellValue("CategoryID")) Then
        '            CheckGridRowsCategory(e.Cell.Row.GetCellValue("CategoryID"), e.Cell.Text)
        '        Else
        '            If e.Cell.Value And Not e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.AS1.ToString And Not e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.AS2.ToString Then
        '                If Not e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.AS1.ToString And Not e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.AS2.ToString Then
        '                    e.Cell.CancelUpdate()
        '                    MessageBox.Show(MessageManager.GetMessage("DE_CL_CHILDCOLUMNLOCKED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
        '                    Exit Sub
        '                End If

        '            Else
        '                CheckGridRowsCategory(e.Cell.Row.GetCellValue("CategoryID"), e.Cell.Text)
        '            End If
        '        End If
        '    End If

        '    ' If the row in un expandable and belongs to category update and dd info or RegistersBlanklistsResearchPublicColumnTitlesandOthers
        '    ' i.e. category 2 Or Category is 3.
        '    If e.Cell.Row.GetCellValue("IsExpandable") = False And _
        '        (e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.UDI.ToString Or e.Cell.Row.GetCellValue("CategoryID") = _
        '         ColumnListCategories.RBC.ToString) Then


        '        ' If user check the NIL field than uncheck the field ND and vice versa.
        '        If e.Cell.Row.GetCellValue("CategoryID") = ColumnListCategories.RBC.ToString Then
        '            Dim pblnIsInvalidValue As Boolean = True
        '            RaiseEvent CheckNDNILStatus(Nothing, True, e.Cell.Row.GetCellValue("Column List"), pblnIsInvalidValue)
        '            If pblnIsInvalidValue = False Then
        '                e.Cell.CancelUpdate()
        '                Exit Sub
        '            End If
        '            'RemoveHandler CheckNDNILStatus, AddressOf CType(Application.OpenForms(lmFomrs), DataHub).check
        '            'If pblnIsInvalidValue = False Then
        '            '    MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_CHANGE"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
        '            '    e.Cell.CancelUpdate()
        '            '    If e.Cell.Column.Header.Caption = "Show" Then
        '            '        If e.Cell.Value = True Then
        '            '            e.Cell.Value = False
        '            '            UncheckChildWithParentUncheck(e.Cell.Row.Cells("EntityID").Value)
        '            '        Else
        '            '            e.Cell.Value = True
        '            '            CheckParentWithChildRow(e.Cell.Row.Cells("EntityID").Value)
        '            '        End If
        '            '    End If
        '            '    Exit Sub
        '            'End If
        '            'If e.Cell.Row.GetCellText(e.Cell.Row.Cells("Show").Column).ToString = "True" Then
        '            '    If pblnIsInvalidValue Then
        '            '        If e.Cell.Column.Key = "NIL" Then
        '            '            If e.Cell.Text = True Then
        '            '                e.Cell.Row.Cells("ND").Value = False
        '            '            End If
        '            '        ElseIf e.Cell.Column.Key = "ND" Then
        '            '            If e.Cell.Text = True Then
        '            '                e.Cell.Row.Cells("NIL").Value = False
        '            '            End If
        '            '        End If
        '            '    End If
        '            'Else
        '            '    If e.Cell.Row.GetCellValue("IsChild") = False Then
        '            '        e.Cell.CancelUpdate()
        '            '    End If
        '            'End If
        '        End If
        '        If e.Cell.Column.Key = "Show" Then
        '            If e.Cell.Row.Cells("Show").Text = True Then
        '                If e.Cell.Row.GetCellValue("IsChild") = False Then
        '                    'Check all the rows with same source id. and also checked row is the parent.
        '                    CheckRowsWithSameSourceName(e.Cell.Row.GetCellValue("SourceID"))
        '                Else
        '                    'Check the parent row If the child row checked.
        '                    CheckParentWithChildRow(e.Cell.Row.GetCellValue("EntityID"))
        '                End If
        '            Else
        '                If e.Cell.Row.GetCellValue("IsChild") = False Then
        '                    'If parent row unchecked, than uncheck its child.
        '                    UncheckChildWithParentUncheck(e.Cell.Row.GetCellValue("EntityID"))
        '                End If
        '            End If
        '        End If
        '    End If
        '    e.Cell.Row.Update()
        '    'Check the expandable row if all the rows are checked of particulare category.
        '    SetParentRowTrueIfAllChildTrue()
        'End If

    End Sub


    ''' <summary>
    ''' Create xml of changed ND/NIL selection of rows.
    ''' </summary>
    ''' <param name="ldtProjects"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Function CreateXML(ByVal ldtProjects As DataTable) As StringBuilder
        Dim i As Integer
        Dim sbXML As New StringBuilder
        Try
            If ldtProjects.Rows.Count > 0 Then
                sbXML.Append("<Root>")
                For i = 0 To ldtProjects.Rows.Count - 1
                    If Not CommonCLL.blnRowBlank(ldtProjects.Rows(i)) Then
                        sbXML.Append("<Row EntityID=""" & ldtProjects.Rows(i)("EntityID").ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                 "IsND=""" & ldtProjects.Rows(i)("IsND").ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                                 "IsNIL=""" & ldtProjects.Rows(i)("IsNIL").ToString().Replace("'", "&apos;").Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace(ControlChars.Quote, "&quot;") & """ " & _
                             "/>")
                        sbXML.Append(vbNewLine)
                    End If
                Next
                sbXML.Append("</Root>")
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
        Return sbXML
    End Function

    ''' <summary>
    ''' Expand collapse group AttributeSet1.
    ''' </summary>
    ''' <param name="Collapse"></param>
    ''' <remarks></remarks>
    Private Sub AttributeSet1(ByVal Collapse As Boolean)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = True And row.GetCellValue("CategoryID") = ColumnListCategories.AS1.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Expand
                Else
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Collapse
                End If
            End If
            If row.GetCellValue("IsExpandable") = False And row.GetCellValue("CategoryID") = ColumnListCategories.AS1.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Hidden = True
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Hidden = False
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Expand Collapse Group UpdatesandDDInfoColumnTitles
    ''' </summary>
    ''' <param name="Collapse"></param>
    ''' <remarks></remarks>
    Private Sub UpdatesandDDInfoColumnTitles(ByVal Collapse As Boolean)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = True And row.GetCellValue("CategoryID") = ColumnListCategories.UDI.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Expand
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Collapse
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
            If row.GetCellValue("IsExpandable") = False And row.GetCellValue("CategoryID") = ColumnListCategories.UDI.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Hidden = True
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Hidden = False
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Expand collapse group RegistersBlanklistsResearchPublicColumnTitlesandOthers.
    ''' </summary>
    ''' <param name="Collapse"></param>
    ''' <remarks></remarks>
    Private Sub RegistersBlanklistsResearchPublicColumnTitlesandOthers(ByVal Collapse As Boolean)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = True And row.GetCellValue("CategoryID") = ColumnListCategories.RBC.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Expand
                Else
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Collapse
                End If
            End If
            If row.GetCellValue("IsExpandable") = False And row.GetCellValue("CategoryID") = ColumnListCategories.RBC.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Hidden = True
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Hidden = False
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Expand Collapse Group PreviousFinalisedListings.
    ''' </summary>
    ''' <param name="Collapse"></param>
    ''' <remarks></remarks>
    Private Sub PreviousFinalisedListings(ByVal Collapse As Boolean)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = True And row.GetCellValue("CategoryID") = ColumnListCategories.PFL.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Expand
                Else
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Collapse
                End If
            End If
            If row.GetCellValue("IsExpandable") = False And row.GetCellValue("CategoryID") = ColumnListCategories.PFL.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Hidden = True
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Hidden = False
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Expand Collapse Group AttributesSet2
    ''' </summary>
    ''' <param name="Collapse"></param>
    ''' <remarks></remarks>
    Private Sub AttributesSet2(ByVal Collapse As Boolean)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = True And row.GetCellValue("CategoryID") = ColumnListCategories.AS2.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Expand
                Else
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Collapse
                End If
            End If
            If row.GetCellValue("IsExpandable") = False And row.GetCellValue("CategoryID") = ColumnListCategories.AS2.ToString Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Hidden = True
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Hidden = False
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' CheckCollapsedExpandRows acc. to category.
    ''' </summary>
    ''' <param name="CategoryId"></param>
    ''' <param name="Collapse"></param>
    ''' <remarks></remarks>
    Private Sub CheckCollapsedExpandRows(ByVal CategoryId As String, ByVal Collapse As Boolean)
        Select Case CategoryId
            Case ColumnListCategories.AS1.ToString
                AttributeSet1(Collapse)

            Case ColumnListCategories.UDI.ToString
                UpdatesandDDInfoColumnTitles(Collapse)

            Case ColumnListCategories.RBC.ToString
                RegistersBlanklistsResearchPublicColumnTitlesandOthers(Collapse)

            Case ColumnListCategories.PFL.ToString
                PreviousFinalisedListings(Collapse)

            Case ColumnListCategories.AS2.ToString
                AttributesSet2(Collapse)
        End Select
    End Sub

    Private Sub ExpandCollapseFL(ByVal Collapse As Boolean, ByVal categoryID As String)
        For Each row As UltraGridRow In grdColumnList.Rows
            If row.GetCellValue("IsExpandable") = True And row.GetCellValue("CategoryID") = categoryID Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Expand
                Else
                    row.Cells("ExpandCollapse").Value = CrystalDataHub.View.My.Resources.Collapse
                End If
            End If
            If row.GetCellValue("IsExpandable") = False And row.GetCellValue("CategoryID") = categoryID Then
                row.Cells("IsCollapsed").Value = Collapse
                If Collapse = True Then
                    row.Hidden = True
                    row.Cells("IsCollapsed").Value = True
                Else
                    row.Hidden = False
                    row.Cells("IsCollapsed").Value = False
                End If
            End If
        Next
    End Sub

    ''' <summary>
    ''' Event Click Cell of UltraWinGrid.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdColumnList_ClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles grdColumnList.ClickCell
        Dim grdData As DataTable
        Dim filterQuery As String
        Dim drow() As DataRow
        Dim nRow As DataRow
        Dim pblnIsInvalidValue As Boolean
        Try
            If e.Cell Is Nothing Then Exit Sub
            If mblnDataHub Then
                If e.Cell.Row.GetCellValue("CategoryID").ToString = ColumnListCategories.RBC.ToString Or e.Cell.Row.GetCellValue("CategoryID").ToString = ColumnListCategories.UDI.ToString And Not e.Cell.Column.Header.Caption.Equals(String.Empty) Then
                    If e.Cell.Row.GetCellValue("IsExpandable") Then
                        If e.Cell.Column.Header.Caption = "Show" Then
                            If CheckInvalidValue(e.Cell.Row.GetCellValue("CategoryID").ToString) = False Then
                                MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_CHANGE"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                                e.Cell.CancelUpdate()
                                Exit Sub
                            End If
                            If CheckLockedColumnInHub(e.Cell.Row.GetCellValue("CategoryID")) Then
                                CheckGridRowsCategory(e.Cell.Row.GetCellValue("CategoryID"), Not e.Cell.Value)
                                e.Cell.CancelUpdate()
                            Else
                                MessageBox.Show(MessageManager.GetMessage("DE_CL_CHILDCOLUMNLOCKED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                                Exit Sub
                            End If
                        End If
                    Else
                        If e.Cell.Column.Header.Caption.Equals("Show") Or e.Cell.Column.Header.Caption.Equals("ND") Or e.Cell.Column.Header.Caption.Equals("NIL") Then
                            RaiseEvent CheckNDNILStatus(e.Cell.Row, True, e.Cell.Row.Cells("Column List").ToString.Trim, pblnIsInvalidValue)
                            If pblnIsInvalidValue = False Then
                                MessageBox.Show(MessageManager.GetMessage("DE_COLUMNLIST_CHANGE"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                                e.Cell.CancelUpdate()
                                Exit Sub
                            End If
                            For Each lobjCurrentDataSource As CurrentDataSources In mstCurrentDataSourcesDataHub
                                If (e.Cell.Row.GetCellValue("Column List").ToString.Trim.Equals(lobjCurrentDataSource.SourceName) Or _
                                    e.Cell.Row.GetCellValue("Column List").ToString.Trim.Equals(lobjCurrentDataSource.SourceDate)) _
                                    AndAlso lobjCurrentDataSource.AccessStatus = SourceAccessbility.Locked.ToString Then
                                    MessageBox.Show(MessageManager.GetMessage("DE_CL_COLUMNLOCKED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                                    e.Cell.CancelUpdate()
                                    Exit Sub
                                End If
                            Next
                            If e.Cell.Column.Header.Caption.Equals("NIL") Or e.Cell.Column.Header.Caption.Equals("ND") Then
                                If e.Cell.Column.Header.Caption = "ND" Then
                                    If e.Cell.Value Is DBNull.Value Then Exit Sub
                                    If mdtAppendNDNIL Is Nothing Then
                                        AddColumnTodtAppendNDNIL()
                                    End If
                                    If Not e.Cell.Value Then
                                        e.Cell.Row.Cells("NIL").Value = False
                                        UpdateNDNILStatus(e.Cell, "ND", True)
                                    Else
                                        UpdateNDNILStatus(e.Cell, "ND", False)
                                    End If

                                ElseIf e.Cell.Column.Header.Caption = "NIL" Then
                                    If e.Cell.Value Is DBNull.Value Then Exit Sub
                                    If mdtAppendNDNIL Is Nothing Then
                                        AddColumnTodtAppendNDNIL()
                                    End If
                                    If Not e.Cell.Value Then
                                        e.Cell.Row.Cells("ND").Value = False
                                        UpdateNDNILStatus(e.Cell, "NIL", True)
                                    Else
                                        UpdateNDNILStatus(e.Cell, "NIL", False)
                                    End If
                                End If
                                'e.Cell.CancelUpdate()
                            End If
                            If e.Cell.Column.Key = "Show" Then
                                If e.Cell.Row.Cells("Show").Value Then
                                    If e.Cell.Row.GetCellValue("IsChild") = False Then
                                        'If parent row unchecked, than uncheck its child.
                                        UncheckChildWithParentUncheck(e.Cell.Row.GetCellValue("EntityID"))
                                        e.Cell.CancelUpdate()
                                    End If
                                Else
                                    If e.Cell.Row.GetCellValue("IsChild") = False Then
                                        'Check all the rows with same source id. and also checked row is the parent.
                                        CheckRowsWithSameSourceName(e.Cell.Row.GetCellValue("SourceID"))
                                        e.Cell.CancelUpdate()
                                    Else
                                        If e.Cell.Row.Cells("Show").Value Then
                                            e.Cell.CancelUpdate()
                                        Else
                                            'Check the parent row If the child row checked.
                                            CheckParentWithChildRow(e.Cell.Row.GetCellValue("EntityID"))
                                        End If
                                    End If
                                End If
                            End If
                            '    End If
                        End If
                    End If
                    e.Cell.Row.Update()
                    SetParentRowTrueIfAllChildTrue()
                ElseIf Not e.Cell.Row.GetCellValue("CategoryID").ToString = ColumnListCategories.RBC.ToString And Not e.Cell.Row.GetCellValue("CategoryID").ToString = ColumnListCategories.UDI.ToString _
                    And e.Cell.Column.Header.Caption = "Show" Then
                    If e.Cell.Row.GetCellValue("IsExpandable") Then
                        CheckGridRowsCategory(e.Cell.Row.GetCellValue("CategoryID"), Not e.Cell.Value)
                        e.Cell.CancelUpdate()
                    Else
                        If e.Cell.Column.Header.Caption = "Show" Then
                            e.Cell.Value = Not e.Cell.Value '.CancelUpdate()
                            e.Cell.CancelUpdate()
                        End If
                    End If
                    e.Cell.Row.Update()
                    SetParentRowTrueIfAllChildTrue()
                End If

                If e.Cell.Column.Key <> "ExpandCollapse" Then Exit Sub
                If grdColumnList.ActiveCell.Row.GetCellValue("IsExpandable") = True Then
                    If grdColumnList.ActiveCell.Row.GetCellValue("IsCollapsed") = False Then
                        CheckCollapsedExpandRows(grdColumnList.ActiveCell.Row.GetCellValue("CategoryID"), True)
                        If mstrCollapsedCategories <> String.Empty Then
                            If mstrCollapsedCategories.Contains(grdColumnList.ActiveCell.Row.GetCellValue("CategoryID")) Then
                                mstrCollapsedCategories = mstrCollapsedCategories.Replace(grdColumnList.ActiveCell.Row.GetCellValue("CategoryID").ToString, "")
                            End If
                        End If
                    Else
                        CheckCollapsedExpandRows(grdColumnList.ActiveCell.Row.GetCellValue("CategoryID"), False)
                        If mstrCollapsedCategories = String.Empty Then
                            mstrCollapsedCategories = grdColumnList.ActiveCell.Row.GetCellValue("CategoryID")
                        Else
                            If Not mstrCollapsedCategories.Contains(grdColumnList.ActiveCell.Row.GetCellValue("CategoryID")) Then
                                mstrCollapsedCategories = mstrCollapsedCategories + "," + grdColumnList.ActiveCell.Row.GetCellValue("CategoryID")
                            End If
                        End If
                    End If
                End If

            Else
                grdData = CType(grdColumnList.DataSource, DataTable)
                If e.Cell.Column.Header.Caption = "ND" Then
                    If e.Cell.Value Is DBNull.Value Then Exit Sub
                    If mdtAppendNDNIL Is Nothing Then
                        AddColumnTodtAppendNDNIL()
                    End If
                    If Not e.Cell.Value Then
                        e.Cell.Row.Cells("NIL").Value = False
                        UpdateNDNILStatus(e.Cell, "ND", True)
                    Else
                        UpdateNDNILStatus(e.Cell, "ND", False)
                    End If

                ElseIf e.Cell.Column.Header.Caption = "NIL" Then
                    If e.Cell.Value Is DBNull.Value Then Exit Sub
                    If mdtAppendNDNIL Is Nothing Then
                        AddColumnTodtAppendNDNIL()
                    End If
                    If Not e.Cell.Value Then
                        e.Cell.Row.Cells("ND").Value = False
                        UpdateNDNILStatus(e.Cell, "NIL", True)
                    Else
                        UpdateNDNILStatus(e.Cell, "NIL", False)
                    End If

                ElseIf e.Cell.Column.Header.Caption = "Show" Then
                    If Not marrColumnListCategories.Contains(e.Cell.Row.GetCellValue("CategoryID")) Then
                        If e.Cell.Row.GetCellValue("EntityID") IsNot DBNull.Value Then
                            If e.Cell.Row.GetCellValue("IsChild") Then
                                ChangeShowValueEntityID(e.Cell.Row.GetCellValue("EntityID"), False)
                            Else
                                ChangeShowValueEntityID(e.Cell.Row.GetCellValue("EntityID"), True)
                            End If
                            If e.Cell.Row.GetCellValue("SourceTypeID") IsNot DBNull.Value Then
                                If e.Cell.Value = False Then
                                    filterQuery = "SourceTypeID = '" + e.Cell.Row.GetCellValue("SourceTypeID").ToString + "' And ListingName ='" + _
                                        e.Cell.Row.GetCellValue("ListingName").ToString + "'"
                                    drow = grdData.Select(filterQuery)
                                    If drow.Length <> 0 Then
                                        For Each row As DataRow In drow
                                            If row("EntityID") Is DBNull.Value And row("SourceID") Is DBNull.Value Then
                                                If row("Column List").ToString.Contains("Date") Then
                                                    'drow(0)("Show") = False
                                                Else
                                                    row("Show") = True
                                                End If
                                            End If
                                        Next
                                    End If
                                End If
                            End If
                        Else
                            If e.Cell.Row.GetCellValue("ListingName") IsNot DBNull.Value Then
                                If e.Cell.Row.GetCellValue("Column List") = mdlDataHubBLLCommon.mstrSpaceIntend + mdlDataHubBLLCommon.mstrSuggestedFinalSuffix _
                                    + " " + e.Cell.Row.GetCellValue("ListingName") Then
                                    If e.Cell.Value Then
                                        'e.Cell.Value = False
                                    Else
                                        'e.Cell.Value = True
                                        filterQuery = "[Column List] = '" + mdlDataHubBLLCommon.mstrCurrentListingColPrefix _
                                            + e.Cell.Row.GetCellValue("ListingName") + "'"
                                        drow = grdData.Select(filterQuery)
                                        If drow.Length <> 0 Then
                                            drow(0)("Show") = True
                                        End If
                                    End If
                                ElseIf e.Cell.Row.GetCellValue("Column List") = mdlDataHubBLLCommon.mstrCurrentListingColPrefix _
                                + e.Cell.Row.GetCellValue("ListingName") Then
                                    If e.Cell.Value Then
                                        'e.Cell.Value = False
                                        filterQuery = "[Column List] = '" + mdlDataHubBLLCommon.mstrSpaceIntend + mdlDataHubBLLCommon.mstrSuggestedFinalSuffix _
                                            + " " + e.Cell.Row.GetCellValue("ListingName") + "'"
                                        drow = grdData.Select(filterQuery)
                                        If drow.Length <> 0 Then
                                            drow(0)("Show") = False
                                        End If
                                    Else

                                    End If
                                Else
                                    If e.Cell.Row.GetCellValue("SourceTypeID") IsNot DBNull.Value Then
                                        If e.Cell.Value = False Then
                                            If e.Cell.Row.GetCellValue("Column List").ToString.Contains("Date") Then
                                                filterQuery = "SourceTypeID = '" + e.Cell.Row.GetCellValue("SourceTypeID").ToString + "' And ListingName ='" + _
                                                e.Cell.Row.GetCellValue("ListingName").ToString + "'"
                                                drow = grdData.Select(filterQuery)
                                                If drow.Length <> 0 Then
                                                    For Each row As DataRow In drow
                                                        If row("EntityID") Is DBNull.Value And row("SourceID") Is DBNull.Value Then
                                                            If row("Column List").ToString.Contains("Date") Then
                                                                'drow(0)("Show") = False
                                                            Else
                                                                row("Show") = True
                                                            End If
                                                        End If
                                                    Next
                                                End If
                                            End If
                                        Else
                                            If Not e.Cell.Row.GetCellValue("Column List").ToString.Contains("Date") And e.Cell.Row.GetCellValue("EntityID") Is DBNull.Value _
                                                And e.Cell.Row.GetCellValue("SourceID") Is DBNull.Value Then
                                                filterQuery = "SourceTypeID = '" + e.Cell.Row.GetCellValue("SourceTypeID").ToString + "' And ListingName ='" + _
                                                e.Cell.Row.GetCellValue("ListingName").ToString + "'"
                                                drow = grdData.Select(filterQuery)
                                                If drow.Length <> 0 Then
                                                    For Each row As DataRow In drow
                                                        If row("EntityID") Is DBNull.Value And row("SourceID") Is DBNull.Value Then
                                                            row("Show") = False
                                                            'If row("Column List").ToString.Contains("Date") Then
                                                            '    drow(0)("Show") = False
                                                            'Else
                                                            '    row("Show") = True
                                                            'End If
                                                        End If
                                                    Next
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                ElseIf e.Cell.Column.Key = "ExpandCollapse" Then
                    If grdColumnList.ActiveCell.Row.GetCellValue("IsExpandable") = True Then
                        If grdColumnList.ActiveCell.Row.GetCellValue("IsCollapsed") = False Then
                            ExpandCollapseFL(True, e.Cell.Row.GetCellValue("CategoryID"))
                        Else
                            ExpandCollapseFL(False, e.Cell.Row.GetCellValue("CategoryID"))
                        End If
                    End If
                ElseIf e.Cell.Column.Key = "SumUpErrors" Then
                    If e.Cell.Activation = Activation.Disabled Then
                        Exit Sub
                    End If
                    If e.Cell.Value Is DBNull.Value Then
                        e.Cell.Value = False
                        Exit Sub
                    End If
                    If e.Cell.Value = False Then
                        e.Cell.Value = True
                    Else
                        e.Cell.Value = False
                    End If
                End If
                If e.Cell.Column.Header.Caption.Equals("Show") Or e.Cell.Column.Header.Caption.Equals("ND") Or e.Cell.Column.Header.Caption.Equals("NIL") Then
                    For Each lobjCurrentDataSource As CurrentDataSources In mstCurrentDataSourcesDataHub
                        If (e.Cell.Row.GetCellValue("Column List").ToString.Trim.Equals(lobjCurrentDataSource.SourceName) Or _
                            e.Cell.Row.GetCellValue("Column List").ToString.Trim.Equals(lobjCurrentDataSource.SourceDate)) _
                            AndAlso lobjCurrentDataSource.AccessStatus = SourceAccessbility.Locked.ToString Then
                            MessageBox.Show(MessageManager.GetMessage("DE_CL_COLUMNLOCKED"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                            e.Cell.CancelUpdate()
                            Exit Sub
                        End If
                    Next
                End If
            End If
            grdColumnList.UpdateData()
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            grdData = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Update the Status of ND/NIL.
    ''' </summary>
    ''' <param name="ugCell"></param>
    ''' <param name="str"></param>
    ''' <remarks></remarks>
    Private Sub UpdateNDNILStatus(ByVal ugCell As UltraGridCell, ByVal str As String, ByVal blnValue As Boolean)
        Dim foundRow() As DataRow
        Dim filterQuery As String
        Dim drRow As DataRow
        If mdtAppendNDNIL Is Nothing Then
            AddColumnTodtAppendNDNIL()
        End If
        If mdtAppendNDNIL.Rows.Count = 0 Then
            drRow = mdtAppendNDNIL.NewRow()
            If str = "ND" Then
                drRow("IsND") = blnValue
                drRow("IsNIL") = False
                drRow("EntityID") = ugCell.Row.GetCellValue("EntityID")
            Else
                drRow("IsND") = False
                drRow("IsNIL") = blnValue
                drRow("EntityID") = ugCell.Row.GetCellValue("EntityID")
            End If
            mdtAppendNDNIL.Rows.Add(drRow)
        Else
            filterQuery = "EntityID = '" + ugCell.Row.GetCellValue("EntityID").ToString + "'"
            foundRow = mdtAppendNDNIL.Select(filterQuery)
            If foundRow.Length <> 0 Then
                For Each row As DataRow In foundRow
                    If str = "ND" Then
                        row("IsND") = blnValue
                        row("IsNIL") = False
                    Else
                        row("IsND") = False
                        row("IsNIL") = blnValue
                    End If
                Next
            Else
                drRow = mdtAppendNDNIL.NewRow()
                If str = "ND" Then
                    drRow("IsND") = blnValue
                    drRow("IsNIL") = False
                    drRow("EntityID") = ugCell.Row.GetCellValue("EntityID")
                Else
                    drRow("IsND") = False
                    drRow("IsNIL") = blnValue
                    drRow("EntityID") = ugCell.Row.GetCellValue("EntityID")
                End If
                mdtAppendNDNIL.Rows.Add(drRow)
            End If
        End If
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="lintEntityID"></param>
    ''' <param name="llblnIsChild"></param>
    ''' <remarks></remarks>
    Private Sub ChangeShowValueEntityID(ByVal lintEntityID As Integer, ByVal llblnIsChild As Boolean)
        Dim filterQuery As String
        Dim drow() As DataRow
        Dim dtGridData As New DataTable
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        If Not llblnIsChild Then
            filterQuery = "EntityID = '" + lintEntityID.ToString + "' And IsChild = False"
        Else
            filterQuery = "EntityID = '" + lintEntityID.ToString + "' And IsChild = True"
        End If
        drow = dtGridData.Select(filterQuery)
        If drow.Length <> 0 Then
            For Each row As DataRow In drow
                If Not llblnIsChild Then
                    row("Show") = True
                Else
                    row("Show") = False
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' Get Sort Order.
    ''' </summary>
    ''' <param name="lstrCode"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetSortOrderID(ByVal lstrCode As String, ByRef lstrCategoryID As String) As Integer
        Dim lsortOrderID As Integer
        If lstrCode = "UPD" Or lstrCode = "DDQ" Or lstrCode = "DDE" Or lstrCode = "DDA" Or lstrCode = "DDI" Then
            lsortOrderID = 2
            lstrCategoryID = ColumnListCategories.UDI.ToString
        ElseIf lstrCode = "REG" Or lstrCode = "RGT" Or lstrCode = "BKL" Or lstrCode = "RSH" Or lstrCode = "PRB" Or lstrCode = "EBL" Or lstrCode = "PBC" Or lstrCode = "PRB" Then
            lsortOrderID = 3
            lstrCategoryID = ColumnListCategories.RBC.ToString
        Else
            lsortOrderID = 4
            lstrCategoryID = ColumnListCategories.PFL.ToString
        End If
        Return lsortOrderID
    End Function

    ''' <summary>
    ''' Add new columns for DE and FL. Add Source Only for FL.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        Dim llstNewColumns As List(Of String)
        Dim lAddNewColumn As AddNewColumn
        Dim ldtGridData As DataTable
        Dim ldrDataRow As DataRow
        Dim lstrCategory As String = String.Empty
        Dim lclsCLM As ColumnListManager
        Dim lstrCategoryID As String = String.Empty
        Dim dataView As DataView
        Dim colRow As UltraGridRow
        Dim lstCurrentDataSources As List(Of CurrentDataSources)
        Dim strDataSource As String
        Try
            lclsCLM = New ColumnListManager
            lAddNewColumn = New AddNewColumn
            lAddNewColumn.mintProjectID = mintProjectID
            lAddNewColumn.mblnColumnList = True
            lAddNewColumn.mblnFLScreen = Not mblnDataHub
            'Open dialog to add new column.
            lAddNewColumn.ShowDialog()
            If lAddNewColumn.mblnCloseNoChange Then Exit Sub
            strDataSource = lAddNewColumn.mstrDataSource
            lstCurrentDataSources = lAddNewColumn.mlstNewAddedColumns
            If lstCurrentDataSources Is Nothing Then Exit Sub
            If lstCurrentDataSources.Item(0).SourceName Is DBNull.Value Then Exit Sub
            If mlstNewAddedColumns Is Nothing Then
                mlstNewAddedColumns = lstCurrentDataSources
            Else
                'If mlstNewAddedColumns.Item(0).SourceName Is DBNull.Value Then Exit Sub
                For Each lstrNewCol As CurrentDataSources In lstCurrentDataSources
                    mlstNewAddedColumns.Add(lstrNewCol)
                Next
            End If
            ldtGridData = New DataTable
            ldtGridData = CType(grdColumnList.DataSource, DataTable)
            If mblnDataHub Then
                If lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.PBC.ToString Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.REG.ToString Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.BKL.ToString Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.RGT.ToString _
                Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.RSH.ToString Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.PRB.ToString Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.EBL.ToString Then
                    CheckCollapsedExpandRows(ColumnListCategories.RBC.ToString, False)
                ElseIf lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.UPD.ToString Or lAddNewColumn.mstrSourceTypeCode = SourceTypeCode.DDI.ToString Then
                    CheckCollapsedExpandRows(ColumnListCategories.UDI.ToString, False)
                End If
            End If
            Dim j As Integer = 0
            For i As Integer = 0 To lstCurrentDataSources.Count - 1
                j = 0
                If mblnDataHub = False Then
                    ExpandCollapseFL(False, lstCurrentDataSources(i).ListingName)
                End If
                If lstCurrentDataSources(i).PublicFilingDateCol IsNot Nothing Or lstCurrentDataSources(i).PublicSourceCol IsNot Nothing Or _
                    lstCurrentDataSources(i).SourceDate IsNot Nothing Or lstCurrentDataSources(i).ResearchSourceCol IsNot Nothing Then
                    If lstCurrentDataSources(i).SourceDate IsNot Nothing Then
                        j = 1
                    End If
                End If
                For index = 0 To j
                    ldrDataRow = ldtGridData.NewRow()
                    ldrDataRow("ExpandCollapse") = DBNull.Value
                    ldrDataRow("Edit") = DBNull.Value
                    ldrDataRow("Show") = True
                    If mblnDataHub Then
                        If index = 0 Then
                            ldrDataRow("Column List") = lstCurrentDataSources(i).SourceName.ToString
                            ldrDataRow("IsChild") = False
                        Else
                            ldrDataRow("Column List") = mstrSpaceIntend + lstCurrentDataSources(i).SourceDate.ToString
                            ldrDataRow("IsChild") = True
                        End If
                    Else
                        If index = 0 Then
                            If lstCurrentDataSources(i).SourceTypeCode = SourceTypeCode.DDI.ToString Then
                                If lstCurrentDataSources(i).ESourceCode = DataSourceCode.DDALCOT.ToString Then
                                    ldrDataRow("Column List") = lstCurrentDataSources(i).SourceName.ToString
                                Else
                                    ldrDataRow("Column List") = mstrSpaceIntend + lstCurrentDataSources(i).SourceName.ToString
                                End If
                            Else
                                ldrDataRow("Column List") = mstrSpaceIntend + lstCurrentDataSources(i).SourceName.ToString
                            End If
                            ldrDataRow("IsChild") = False
                        Else
                            If Not lstCurrentDataSources(i).SourceDate Is Nothing Then
                                ldrDataRow("Column List") = mstrSpaceIntend + mstrTwoSpaces + lstCurrentDataSources(i).SourceDate.ToString
                            End If
                            ldrDataRow("IsChild") = True
                        End If
                    End If
                    ldrDataRow("NIL") = lstCurrentDataSources(i).IsNIL
                    ldrDataRow("ND") = lstCurrentDataSources(i).IsND
                    ldrDataRow("EntityID") = lclsCLM.GetEntityID(lstCurrentDataSources(i).SourceName.ToString)
                    ldrDataRow("IsExpandable") = False
                    ldrDataRow("SourceID") = lstCurrentDataSources(i).ESourceID
                    ldrDataRow("Source") = lstCurrentDataSources(i).ESourceName
                    If mblnDataHub Then
                        ldrDataRow("SortOrderID") = GetSortOrderID(lAddNewColumn.mstrSourceTypeCode, lstrCategoryID)
                        ldrDataRow("CategoryID") = lstrCategoryID
                    Else
                        If index = 0 Then
                            If lstCurrentDataSources(i).SourceTypeCode = SourceTypeCode.RGT.ToString Or lstCurrentDataSources(i).SourceTypeCode = SourceTypeCode.DDI.ToString _
                            Or lstCurrentDataSources(i).SourceTypeCode = SourceTypeCode.BKL.ToString Or lstCurrentDataSources(i).SourceTypeCode = SourceTypeCode.EBL.ToString Or _
                            lstCurrentDataSources(i).SourceTypeCode = SourceTypeCode.UPD.ToString Then
                                If lstCurrentDataSources(i).ESourceID <> DataSourceCode.DDALCOT Then
                                    AddSourceTypeFL(lstCurrentDataSources(i), strDataSource)
                                End If
                            End If
                        End If
                        ldrDataRow("SortOrderID") = GetSortOrderID(lstCurrentDataSources(i).ListingName, CType(grdColumnList.DataSource, DataTable))
                        ldrDataRow("CategoryID") = lstCurrentDataSources(i).ListingName
                        ldrDataRow("ListingID") = lstCurrentDataSources(i).ListingID
                        ldrDataRow("ListingName") = lstCurrentDataSources(i).ListingName
                        ldrDataRow("SourceTypeID") = GetSourceTypeId(lstCurrentDataSources(i).SourceTypeCode)
                        ldrDataRow("SortOrder") = GetSortOrderColumnList(lstCurrentDataSources(i).SourceTypeCode)
                    End If
                    ldtGridData.Rows.Add(ldrDataRow)
                Next
            Next
            If mblnDataHub Then
                dataView = New DataView(ldtGridData)
                dataView.Sort = "SortOrderID DESC"
                grdColumnList.DisplayLayout.Bands(0).SortedColumns.Add("SortOrderID", False, True)
            Else
                'SetSortOrder(ldtGridData)
                SetGroupOrder(ldtGridData)
                'ldtGridData.DefaultView.Sort = "GroupID Asc"
                grdColumnList.DisplayLayout.Bands(0).SortedColumns.Add("GroupID", False, True)
                'MakeGroupSourceTypeID()
            End If
            colRow = Me.grdColumnList.Rows.OfType(Of UltraGridRow)().ToList().Find(Function(row) row.Cells("Column List").Text.Equals(lstCurrentDataSources(0).SourceName.ToString, StringComparison.CurrentCultureIgnoreCase))
            If colRow IsNot Nothing Then
                colRow.Selected = True
                colRow.Activated = True
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, Me.Text, mintProjectID)
        Finally
            ldrDataRow = Nothing
            ldtGridData = Nothing
            lAddNewColumn = Nothing
            llstNewColumns = Nothing
            lclsCLM = Nothing
            dataView = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Add Source Type Finalise.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Sub AddSourceTypeFL(ByVal lstCurrentDataSources As CurrentDataSources, ByVal lstrDataSource As String)
        Dim foundRows() As DataRow
        Dim filterQuery As String
        Dim dtGridData As DataTable
        Dim dRow As DataRow
        Dim strColumnName As String
        Dim intValue As Integer = GetSourceTypeId(lstCurrentDataSources.SourceTypeCode)
        If lstCurrentDataSources.SourceTypeCode = SourceTypeCode.UPD.ToString Then
            strColumnName = mstrUpdatesColPrefix + lstCurrentDataSources.ListingName
        ElseIf lstCurrentDataSources.SourceTypeCode = SourceTypeCode.DDI.ToString Then
            strColumnName = mstrDDInfoColPrefix + lstCurrentDataSources.ListingName
        ElseIf lstCurrentDataSources.SourceTypeCode = SourceTypeCode.RGT.ToString Then
            strColumnName = mstrRegisterColPrefix + lstCurrentDataSources.ListingName
        ElseIf lstCurrentDataSources.SourceTypeCode = SourceTypeCode.BKL.ToString Then
            strColumnName = mstrBanklistColPrefix + lstCurrentDataSources.ListingName
        Else
            strColumnName = lstrDataSource + " " + lstCurrentDataSources.ListingName
        End If
        filterQuery = "SourceTypeID ='" + intValue.ToString + "' And [Column List] = '" + strColumnName + "'"
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length = 0 Then
            dRow = dtGridData.NewRow()
            dRow("ExpandCollapse") = DBNull.Value
            dRow("Edit") = DBNull.Value
            dRow("Column List") = strColumnName
            dRow("SourceParent") = True
            dRow("Show") = True
            dRow("CategoryID") = lstCurrentDataSources.ListingName
            dRow("IsExpandable") = False
            dRow("SortOrderID") = GetSortOrderID(lstCurrentDataSources.ListingName, dtGridData)
            dRow("ListingID") = lstCurrentDataSources.ListingID
            dRow("ListingName") = lstCurrentDataSources.ListingName
            dRow("SourceTypeID") = GetSourceTypeId(lstCurrentDataSources.SourceTypeCode)
            dRow("SortOrder") = GetSortOrderColumnList(lstCurrentDataSources.SourceTypeCode)
            dtGridData.Rows.Add(dRow)
            If lstCurrentDataSources.SourceTypeCode = SourceTypeCode.UPD.ToString Or lstCurrentDataSources.SourceTypeCode = SourceTypeCode.DDI.ToString Then
                If lstCurrentDataSources.ESourceCode = DataSourceCode.DDALCOT.ToString Then Exit Sub
                dRow = dtGridData.NewRow()
                dRow("ExpandCollapse") = DBNull.Value
                dRow("Edit") = DBNull.Value
                dRow("Column List") = mstrSpaceIntend + strColumnName + mstrSourceDateColSuffix
                dRow("SourceParent") = False
                dRow("Show") = True
                dRow("CategoryID") = lstCurrentDataSources.ListingName
                dRow("IsExpandable") = False
                dRow("SortOrderID") = GetSortOrderID(lstCurrentDataSources.ListingName, dtGridData)
                dRow("ListingID") = lstCurrentDataSources.ListingID
                dRow("ListingName") = lstCurrentDataSources.ListingName
                dRow("SourceTypeID") = GetSourceTypeId(lstCurrentDataSources.SourceTypeCode)
                dRow("SortOrder") = GetSortOrderColumnList(lstCurrentDataSources.SourceTypeCode)
                dtGridData.Rows.Add(dRow)
            End If
        End If
    End Sub

    Private Sub AddESourceFL(ByVal lstCurrentDataSources As CurrentDataSources)
        Dim foundRows() As DataRow
        Dim filterQuery As String
        Dim dtGridData As DataTable
        Dim dRow As DataRow
        Dim intValue As Integer = lstCurrentDataSources.ESourceID
        filterQuery = "SourceID ='" + intValue.ToString + "' And [Column List] = '" + mdlDataHubBLLCommon.mstrSpaceIntend + lstCurrentDataSources.ESourceName + "'"
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length = 0 Then
            dRow = dtGridData.NewRow()
            dRow("ExpandCollapse") = DBNull.Value
            dRow("Edit") = DBNull.Value
            dRow("Column List") = mdlDataHubBLLCommon.mstrSpaceIntend + lstCurrentDataSources.ESourceName '+ " " + lstCurrentDataSources.ListingName
            dRow("Show") = True
            dRow("ND") = DBNull.Value ' lstCurrentDataSources.IsND
            dRow("NIL") = DBNull.Value ' lstCurrentDataSources.IsNIL
            dRow("CategoryID") = lstCurrentDataSources.ListingName
            dRow("IsExpandable") = False
            dRow("SourceID") = lstCurrentDataSources.ESourceID
            dRow("EntityID") = DBNull.Value
            dRow("Source") = DBNull.Value
            dRow("SortOrderID") = 1
            dRow("ListingID") = lstCurrentDataSources.ListingID
            dRow("ListingName") = lstCurrentDataSources.ListingName
            dRow("SourceTypeID") = GetSourceTypeId(lstCurrentDataSources.SourceTypeCode)
            dtGridData.Rows.Add(dRow)
        End If
    End Sub

    Private Function GetGroupID(ByVal lintSourceTypeID As String) As Integer
        Dim foundRows() As DataRow
        Dim filterQuery As String
        Dim dtGridData As DataTable
        'Dim dRow As DataRow
        Dim returnValue As Integer = 0
        'Dim intValue As Integer = lstCurrentDataSources.ESourceID
        filterQuery = "SourceTypeID ='" + lintSourceTypeID.ToString + "'"
        dtGridData = CType(grdColumnList.DataSource, DataTable)
        foundRows = dtGridData.Select(filterQuery)
        If foundRows.Length > 0 Then
            For Each row As DataRow In foundRows
                If row("GroupID") IsNot DBNull.Value Then
                    returnValue = row("GroupID")
                End If
            Next
        End If
        Return returnValue
    End Function


    ''' <summary>
    ''' Retrive SourceType ID.
    ''' </summary>
    ''' <param name="lstrSource"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetSourceTypeID(ByVal lstrSource As String) As Integer
        If lstrSource = SourceTypeCode.BKL.ToString Then
            Return SourceTypeCode.BKL
        ElseIf lstrSource = SourceTypeCode.DDI.ToString Then
            Return SourceTypeCode.DDI
        ElseIf lstrSource = SourceTypeCode.EBL.ToString Then
            Return SourceTypeCode.EBL
        ElseIf lstrSource = SourceTypeCode.EPB.ToString Then
            Return SourceTypeCode.EPB
        ElseIf lstrSource = SourceTypeCode.FND.ToString Then
            Return SourceTypeCode.FND
        ElseIf lstrSource = SourceTypeCode.INV.ToString Then
            Return SourceTypeCode.INV
        ElseIf lstrSource = SourceTypeCode.PBC.ToString Then
            Return SourceTypeCode.PBC
        ElseIf lstrSource = SourceTypeCode.PRB.ToString Then
            Return SourceTypeCode.PRB
        ElseIf lstrSource = SourceTypeCode.REG.ToString Then
            Return SourceTypeCode.REG
        ElseIf lstrSource = SourceTypeCode.RGT.ToString Then
            Return SourceTypeCode.RGT
        ElseIf lstrSource = SourceTypeCode.RSH.ToString Then
            Return SourceTypeCode.RSH
        ElseIf lstrSource = SourceTypeCode.UPD.ToString Then
            Return SourceTypeCode.UPD
        End If
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="lstrSource"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetSourceTypeCode(ByVal lstrSource As String) As String
        If lstrSource = SourceTypeCode.BKL Then
            Return SourceTypeCode.BKL.ToString
        ElseIf lstrSource = SourceTypeCode.DDI Then
            Return SourceTypeCode.DDI.ToString
        ElseIf lstrSource = SourceTypeCode.EBL Then
            Return SourceTypeCode.EBL.ToString
        ElseIf lstrSource = SourceTypeCode.EPB Then
            Return SourceTypeCode.EPB.ToString
        ElseIf lstrSource = SourceTypeCode.FND Then
            Return SourceTypeCode.FND.ToString
        ElseIf lstrSource = SourceTypeCode.INV Then
            Return SourceTypeCode.INV.ToString
        ElseIf lstrSource = SourceTypeCode.PBC Then
            Return SourceTypeCode.PBC.ToString
        ElseIf lstrSource = SourceTypeCode.PRB Then
            Return SourceTypeCode.PRB.ToString
        ElseIf lstrSource = SourceTypeCode.REG Then
            Return SourceTypeCode.REG.ToString
        ElseIf lstrSource = SourceTypeCode.RGT Then
            Return SourceTypeCode.RGT.ToString
        ElseIf lstrSource = SourceTypeCode.RSH Then
            Return SourceTypeCode.RSH.ToString
        ElseIf lstrSource = SourceTypeCode.UPD Then
            Return SourceTypeCode.UPD.ToString
        End If
    End Function
#End Region

    ''' <summary>
    ''' Mouse over on Alpha ShortCut header.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdColumnList_MouseEnterElement(ByVal sender As Object, ByVal e As Infragistics.Win.UIElementEventArgs) Handles grdColumnList.MouseEnterElement
        Dim tipInfo As Infragistics.Win.UltraWinToolTip.UltraToolTipInfo
        Dim lColHeader As ColumnHeader
        Dim acell As UltraGridCell
        Dim lobjCurrentDataSources As CurrentDataSources = Nothing
        Dim lstrUserNames As String = ""
        acell = e.Element.GetContext(GetType(Infragistics.Win.UltraWinGrid.UltraGridCell))

        lColHeader = e.Element.GetContext(GetType(Infragistics.Win.UltraWinGrid.ColumnHeader))
        If Not lColHeader Is Nothing Then
            If lColHeader.Caption = "Alpha Shortcuts" Then
                tipInfo = New Infragistics.Win.UltraWinToolTip.UltraToolTipInfo(MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_1.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_2.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_3.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_4.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_5.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_6.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_7.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_8.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_9.ToString) _
                                                                                + Environment.NewLine + MessageManager.GetMessage(DBResult.FL_ALPHA_SHORTCUT_10.ToString), _
                                                                                ToolTipImage.Info, "Shortcut", DefaultableBoolean.True)
                UltraToolTipManager1.Enabled = True
                UltraToolTipManager1.SetUltraToolTip(sender, tipInfo)
                UltraToolTipManager1.ShowToolTip(sender)
                Exit Sub
            End If
        End If
    End Sub

    ''' <summary>
    ''' Keypress event for UltraWinGrid.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdColumnList_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles grdColumnList.KeyPress
        Dim lstCDS As New CurrentDataSources
        If Not mblnDataHub Then
            If grdColumnList.ActiveCell Is Nothing Then Exit Sub
            If Not Char.IsLetter(e.KeyChar) Then
                e.Handled = True
                Exit Sub
            End If
            If grdColumnList.ActiveCell.Column.Header.Caption = "Alpha Shortcuts" Then
                If Char.IsLetter(e.KeyChar) Then
                    If CheckShortCut(grdColumnList.ActiveCell, e.KeyChar.ToString.ToUpper) Then
                        e.KeyChar = Char.ToUpper(e.KeyChar)
                    Else
                        MessageBox.Show(MessageManager.GetMessage("CHANGE_SHORTCUT"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        e.Handled = True
                    End If
                Else
                    MessageBox.Show(MessageManager.GetMessage("CHAR_LETTER"), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                    grdColumnList.ActiveCell.Value = String.Empty
                    e.Handled = True
                End If
            End If
        End If
        grdColumnList.UpdateData()
    End Sub

    ''' <summary>
    ''' ShortCut for alpha shortcuts.
    ''' </summary>
    ''' <param name="activeCell"></param>
    ''' <param name="lstrShortCut"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CheckShortCut(ByVal activeCell As UltraGridCell, ByVal lstrShortCut As String) As Boolean
        Dim filterQuery As String = String.Empty
        Dim foundRows() As DataRow
        Dim dtData As New DataTable
        dtData = CType(grdColumnList.DataSource, DataTable)
        filterQuery = "ListingID = '" + activeCell.Row.GetCellValue("ListingID").ToString + "' And [Alpha Shortcuts] = '" + lstrShortCut + "'"
        foundRows = dtData.Select(filterQuery)
        If foundRows.Length > 0 Then
            Return False
        End If
        Return True
    End Function
End Class

Public Class NoRowBorders_DrawFilter
    Implements IUIElementDrawFilter

    Public Function DrawElement(ByVal drawPhase As Infragistics.Win.DrawPhase, ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Boolean Implements Infragistics.Win.IUIElementDrawFilter.DrawElement
        Select Case drawPhase
            Case drawPhase.BeforeDrawBorders
                Return True
            Case drawPhase.AfterDrawElement
                Dim aCellUIElement As CellUIElement = CType(drawParams.Element, CellUIElement)
                drawParams.DrawBorders(UIElementBorderStyle.Solid, (Border3DSide.Right), Rectangle.Inflate(aCellUIElement.Rect, 0, 0))
                drawParams.DrawBorders(UIElementBorderStyle.Solid, Border3DSide.Top, Rectangle.Inflate(aCellUIElement.Rect, 0, 0))
                Return True
        End Select
    End Function

    Public Function GetPhasesToFilter(ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Infragistics.Win.DrawPhase Implements Infragistics.Win.IUIElementDrawFilter.GetPhasesToFilter
        If TypeOf drawParams.Element Is CellUIElement Then
            Return DrawPhase.AfterDrawElement Or DrawPhase.BeforeDrawBorders
        End If
    End Function
End Class

Public Class NoRowBorders_DrawFilters
    Implements IUIElementDrawFilter

    Public Function DrawElement(ByVal drawPhase As Infragistics.Win.DrawPhase, ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Boolean Implements Infragistics.Win.IUIElementDrawFilter.DrawElement
        Select Case drawPhase
            Case drawPhase.BeforeDrawBorders
                Return True
            Case drawPhase.AfterDrawElement
                Dim aCellUIElement As CellUIElement = CType(drawParams.Element, CellUIElement)
                drawParams.DrawBorders(UIElementBorderStyle.Solid, Border3DSide.Right, Rectangle.Inflate(aCellUIElement.Rect, 0, 0))
                'drawParams.DrawBorders(
                ''drawParams.DrawBorder's(UIElementBorderStyle.Solid, Border3DSide.Top, Rectangle.Inflate(aCellUIElement.Rect, 0, 0))
                Return True
        End Select
    End Function

    Public Function GetPhasesToFilter(ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Infragistics.Win.DrawPhase Implements Infragistics.Win.IUIElementDrawFilter.GetPhasesToFilter
        If TypeOf drawParams.Element Is CellUIElement Then
            Return DrawPhase.AfterDrawElement Or DrawPhase.BeforeDrawBorders
        End If
    End Function
End Class
